Link Search Menu Expand Document

Python: HTML/CSS to Image

Generate Images and PDFs with Python. Renders exactly like Google Chrome.

Render PNG, JPG, or WebP images + PDFs with Python from HTML/CSS or reusable dynamic templates.

Live demo Get an API Key


Generating images with Python

  1. The API takes your HTML/CSS and runs it inside a real instance of Google Chrome to convert your HTML into an image.
  2. Use Python to send the API your HTML/CSS.
  3. You’ll get back JSON with the URL to your generated image.

For more details on how this works, see Creating an image.

Example API response:

{
  "url": "https://hcti.io/v1/image/be4c5118-fe19-462b-a49e-48cf72697a9d",
  "id": "be4c5118-fe19-462b-a49e-48cf72697a9d"
}

Image generated with Python. Convert HTML to an image using Python.

Authentication with Python

The API uses HTTP Basic authentication.

Your username is your User ID and your password is your API Key. Both of these are available from the dashboard. The Python code sample demonstrates how to authenticate your request.

You can sign up for a free API key to get started.

Free API Key for Python


Python example code

This Python code example sends an HTTP POST to the https://hcti.io/v1/image API to convert your HTML/CSS to an image.

# pip3 install requests
import requests

HCTI_API_ENDPOINT = "https://hcti.io/v1/image"
# Retrieve these from https://htmlcsstoimage.com/dashboard
HCTI_API_USER_ID = 'your-user-id'
HCTI_API_KEY = 'your-api-key'

data = { 'html': "<div class='box'>Hello, world!</div>",
         'css': ".box { color: white; background-color: #0f79b9; padding: 10px; font-family: Roboto }",
         'google_fonts': "Roboto" }

image = requests.post(url = HCTI_API_ENDPOINT, data = data, auth=(HCTI_API_USER_ID, HCTI_API_KEY))

print("Your image URL is: %s"%image.json()['url'])
# https://hcti.io/v1/image/7ed741b8-f012-431e-8282-7eedb9910b32

Need help?

Talk to a human. Please email us support@htmlcsstoimage.com with any questions and we’ll gladly help you get started.


Back to top

Built with extensive integration tests and serious care for developer happiness.
© 2018-2026 Code Happy, LLC.

Page last modified: Jul 9 2026 at 03:30 PM.

Edit this page on GitHub.