# HTML to Image: Render HTML and CSS to PNG, JPEG or PDF (`forgeloop/html-to-image`) Actor

Render your own HTML and CSS to PNG, JPEG, WebP or PDF with Chromium. Templates with {{variables}}, batches of up to 500 items, Google Fonts, retina scale, transparent background, crop to element. For OG images, certificates and invoices in Make, n8n, Zapier.

- **URL**: https://apify.com/forgeloop/html-to-image.md
- **Developed by:** [Markus Heiß](https://apify.com/forgeloop) (community)
- **Categories:** Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 image rendereds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## HTML to Image: Render HTML and CSS to PNG, JPEG or PDF

Render HTML and CSS that you supply into PNG, JPEG, WebP or PDF files with a real Chromium browser. Put `{{placeholders}}` in your markup, pass variables, and get one file per render with a direct download link. Send a list of items to render hundreds of images from one template in a single run.

Built for automations: Open Graph and social images, certificates, invoices, receipts, charts, email banners, badges and thumbnails, generated from Make, n8n, Zapier, your backend or an AI agent. You send markup and data, you get back file URLs.

For screenshots of existing websites by URL, use our [Website Screenshot](https://apify.com/forgeloop/website-screenshot) Actor. This Actor is for HTML you write or generate yourself.

### What it does

- **Renders your HTML** as a fragment (`<div>...</div>`) or a full document, with optional extra CSS. Page margins are 0, so a 1200 x 630 element fills a 1200 x 630 image.
- **Fills templates:** `{{name}}` inserts a value HTML-escaped, `{{{name}}}` inserts it raw (for markup or JSON arrays in scripts), `{{user.name}}` reads nested values. Unknown placeholders become empty and show up in `missingVariables`.
- **Batch mode:** a list of items, each with its own variables and label, renders one file per item from the same template. Up to 500 items per run.
- **Built-in templates** for people who only want to send data: an Open Graph card (1200 x 630) and a certificate (1600 x 1131).
- **Four formats:** PNG (lossless, transparency), JPEG and WebP (small files, quality setting), PDF (selectable text, custom size or A3, A4, A5, Letter, Legal, portrait or landscape).
- **Sharp images:** pixel density 1, 2 or 3 for retina output.
- **Crop to an element** with a CSS selector, or capture the full content height.
- **Transparent background** for PNG and WebP, for logos, badges and overlays.
- **Google Fonts by name**, and it waits until web fonts have loaded. Images, fonts and scripts from public https and http URLs load normally, so Chart.js or other libraries from a CDN work.
- **Safe by design:** the page cannot reach private or local network addresses, files on the server, or video and social platforms. See Limits.

### Use cases

- **Open Graph and social images:** one branded card per blog post, product or release, generated when the content is published.
- **Certificates:** a personalized certificate per course participant as PNG or PDF.
- **Invoices and receipts:** HTML invoice templates to A4 or Letter PDF from your order data.
- **Charts and reports:** render a Chart.js or SVG chart to an image for an email or a Slack message.
- **Email banners and badges:** personalized header images, status badges, score cards.
- **AI agents:** let an agent write HTML and turn it into an image or PDF it can share.

### Input

| Field | Description | Default |
|---|---|---|
| HTML | The markup to render, with `{{placeholders}}`. Max 2 MB. | |
| CSS | Extra CSS for the head. Placeholders work here too. | |
| Template | `custom` (your HTML), `og-card` or `certificate` | `custom` |
| Variables | Values for the placeholders. Defaults for all items. | |
| Items (batch) | List of objects, one file each: `{"label": "anna", "name": "Anna"}` or `{"label": "anna", "variables": {...}}` | |
| Output format | `png`, `jpeg`, `webp` or `pdf` | `png` |
| Width, Height | Viewport in CSS pixels, 16 to 4096 | 1200 x 630 |
| Pixel density | 1, 2 or 3 | 1 |
| Quality | JPEG and WebP, 1 to 100 | 90 |
| Transparent background | PNG and WebP only | off |
| Crop to element | CSS selector like `.card` or `#chart` | |
| Full page | Capture the full content height, up to 10,000 px | off |
| Google Fonts | Family names like `Inter` or `Inter:wght@400;700` | |
| Wait for fonts | Wait until web fonts have loaded | on |
| Extra wait (ms) | For JavaScript charts or animations, 0 to 10,000 | 0 |
| PDF paper size | `custom` (width x height), `A4`, `A5`, `A3`, `Letter`, `Legal` | `custom` |
| PDF landscape | For the paper sizes | off |
| Escape variables | Off makes `{{name}}` insert raw HTML | on |
| File label | Names the file of a single render | |
| Parallel renders | 1 to 5 | 2 |

Example, one Open Graph image from your own HTML:

```json
{
  "html": "<div class=\"card\"><h1>{{title}}</h1><p>{{subtitle}}</p></div>",
  "css": ".card { width: 1200px; height: 630px; box-sizing: border-box; padding: 80px; background: #0f172a; color: #fff; font-family: Inter, sans-serif; } h1 { font-size: 76px; }",
  "variables": { "title": "Version 2.0 is here", "subtitle": "Faster renders, new templates" },
  "googleFonts": ["Inter:wght@400;700"],
  "label": "og-release-2"
}
```

Example, three certificates as PDF from the built-in template:

```json
{
  "template": "certificate",
  "format": "pdf",
  "variables": { "date": "21 November 2026", "issuer": "Automation Academy" },
  "items": [
    { "label": "cert-001", "name": "Example Company GmbH" },
    { "label": "cert-002", "name": "Sample Studio Ltd" },
    { "label": "cert-003", "name": "Demo Industries Inc" }
  ]
}
```

### Output

One dataset row per file. The file itself is in the run's key-value store, and `fileUrl` links to it directly:

```json
{
  "index": 1,
  "label": "og-release-2",
  "format": "png",
  "width": 1200,
  "height": 630,
  "pages": null,
  "bytes": 338878,
  "contentType": "image/png",
  "key": "og-release-2.png",
  "fileUrl": "https://api.apify.com/v2/key-value-stores/aBcD1234/records/og-release-2.png?signature=x1Y2z3",
  "missingVariables": [],
  "blockedRequests": [],
  "renderMs": 1180,
  "error": null
}
```

- `index` is the position of the item in your list, starting at 1. A single render has index 1.
- `width` and `height` are the real pixel size of the image, so pixel density 2 gives 2400 x 1260 for a 1200 x 630 viewport. For PDF they are the page size in CSS pixels (96 per inch), and `pages` is the page count.
- `key` is the record name in the key-value store. It comes from the label, or `image-001` without one. Duplicate labels get the index appended.
- `fileUrl` is a signed link. It opens the file without an API token for as long as the run's storage is kept.
- `missingVariables` lists placeholders that had no value. They were rendered as empty text.
- `blockedRequests` lists up to 10 URLs the page tried to load that were refused (private addresses, video platforms, non-http schemes).
- A failed item has `error` set and no file, for example `No visible element matches the selector ".card".`

Export the dataset as JSON, CSV or Excel, or read it through the Apify API. In Make, n8n or Zapier, run the Actor synchronously and read `fileUrl` from the dataset items.

### Pricing

Pay per file: 0.002 USD per rendered file, so 2.00 USD per 1,000 images or PDFs. Invalid items, timeouts and other errors are free. Set the maximum charge in Apify to cap the cost of a run. The run stops cleanly when the limit is reached.

Each run also has a start fee of 0.00005 USD per GB of memory, which Apify shows as Actor Start, plus the platform usage of the run.

### Limits

- Max 500 items per run. Items beyond 500 are skipped and reported in one error row. Split larger lists into several runs.
- Max 2 MB of HTML and CSS. Load large images from URLs instead of embedding them as base64.
- Max 30 seconds per item, including loading fonts and images. A page that takes longer gets an error row and the run goes on.
- Extra wait up to 10 seconds. Full page captures stop at 10,000 px height, or 16,384 device pixels at pixel density 2 and 3 (8,192 and 5,461 CSS pixels).
- Large retina or full-page images need a lot of browser memory. The Actor then renders fewer items at the same time to fit into the run's memory. If the browser still runs out of memory, the item is retried once and then gets an error row. Give the run more memory for big batches at pixel density 3.
- The page can load resources only from public http and https addresses. Requests to private and local networks (127.0.0.1, 10.x, 192.168.x, 169.254.x, localhost and the like), `file://` URLs, WebSockets and WebRTC are blocked. Pages from YouTube, TikTok, Instagram, Vimeo, Facebook, X and similar platforms are not loaded.
- Downloads and service workers are disabled. JavaScript runs, so charts and libraries work.
- Relative URLs in your HTML have no base address. Use absolute URLs or add a `<base href>` tag.
- Some image hosts refuse automated requests. Those images stay empty. Host important assets yourself or embed small ones as data URLs.
- Crop to element and transparency are not used for PDF. For PDF, CSS `@page` rules win over the paper size setting, and print styles (`@media print`) apply.
- Files stay in the run's key-value store for the data retention period of your Apify plan. Copy them elsewhere if you need them longer.

### Data source, permitted use and legal

- **Data source:** The HTML, CSS and variables you put into the input. The Actor renders them in a Chromium browser and loads only the external resources your HTML references, such as fonts and images from public URLs.
- **Your content:** You are responsible for the markup, text, images, fonts and brands in your input and in the files it produces. Use only content you have the rights to, and respect the licenses of fonts and libraries you load.
- **Snapshot:** Each file shows the page as it rendered at the time of the run. We do not guarantee that external resources load or look the same on every run.
- **For business use:** This Actor is offered to businesses only, not to consumers.
- **Permitted use:** Do not use it to create misleading documents, fake certificates or invoices presented as genuine, or content that infringes the rights of others.
- **Your responsibility:** You choose the input and decide what happens with the results. If your input or the results contain personal data, you are the controller and need your own legal basis.
- **No circumvention:** The Actor loads public resources as a normal browser. It does not bypass logins, paywalls, rate limits, blocks or access restrictions, and it blocks requests to private networks.
- **Request volume:** Each render loads only the resources its HTML references, at most 5 renders at the same time. Do not use it to put load on third-party servers.
- **Provider:** forgeloop, Markus Heiss, Austria. [Imprint](https://devhem.github.io/forgeloop-legal/imprint.html), [Privacy Notice](https://devhem.github.io/forgeloop-legal/privacy.html), [Terms of Use](https://devhem.github.io/forgeloop-legal/terms.html).

### Questions and issues

Open an issue on the Actor page.

# Actor input Schema

## `html` (type: `string`):

The HTML to render. A fragment like <div>...</div> or a full document. Placeholders: {{name}} inserts a variable HTML-escaped, {{{name}}} inserts it raw, {{user.name}} reads nested values. Max 2 MB. Ignored when a built-in template is selected.

## `css` (type: `string`):

Optional CSS, added in a <style> tag in the head. Placeholders work here too. Page margins are already 0.

## `template` (type: `string`):

Custom uses your HTML above. The built-in templates need only variables. og-card (1200 x 630): tag, title, subtitle, brand, url, background, color. certificate (1600 x 1131): kicker, title, presentedTo, name, description, date, dateLabel, issuer, issuerLabel, accent.

## `variables` (type: `object`):

Values for the {{placeholders}}, like {"title": "Hello"}. Used for a single render, and as defaults for every item below. Unknown placeholders become empty and are listed in missingVariables.

## `items` (type: `array`):

Render many files from one template. Each item is an object of variables, like {"label": "alice", "name": "Alice"}, or {"label": "alice", "variables": {...}}. The label names the file. Each item is one charged file. Max 500 items per run, more are skipped.

## `format` (type: `string`):

PNG keeps every pixel and supports transparency. JPEG and WebP give smaller files. PDF keeps text selectable.

## `width` (type: `integer`):

Viewport width in CSS pixels, 16 to 4096. Also the PDF page width for the custom paper size. Default 1200, or the size of the built-in template.

## `height` (type: `integer`):

Viewport height in CSS pixels, 16 to 4096. Default 630, or the size of the built-in template.

## `deviceScaleFactor` (type: `integer`):

1 gives an image exactly width x height. 2 doubles both sides for sharp retina images, 3 triples them.

## `quality` (type: `integer`):

1 to 100. Higher means better quality and bigger files.

## `transparentBackground` (type: `boolean`):

PNG and WebP only. Areas without a background stay transparent, for logos, badges and overlays.

## `selector` (type: `string`):

Capture only the first element that matches, for example .card or #chart. Empty captures the viewport. Not used for PDF.

## `fullPage` (type: `boolean`):

Capture the whole content height instead of the viewport, up to 10,000 px. For PDF with the custom paper size the page grows to the content height.

## `googleFonts` (type: `array`):

Font families to load from Google Fonts, then use them in your CSS. A name like Inter, or a name with weights like Inter:wght@400;700.

## `waitForFonts` (type: `boolean`):

Wait until all web fonts have loaded before the capture.

## `waitMs` (type: `integer`):

Wait this long after loading, for JavaScript charts or animations. 0 to 10,000.

## `pdfPaperFormat` (type: `string`):

Custom uses width and height above. A @page size rule in your CSS wins over this setting.

## `pdfLandscape` (type: `boolean`):

Turn the paper sideways. Only for the paper sizes, not for custom.

## `escapeHtml` (type: `boolean`):

On: {{name}} inserts text safely, so < and & show as characters. Off: {{name}} inserts raw HTML like {{{name}}}.

## `label` (type: `string`):

Names the file of a single render, like og-release-2. Items use their own label.

## `maxConcurrency` (type: `integer`):

How many items are rendered at the same time. 1 to 5.

## Actor input object example

```json
{
  "html": "<div class=\"card\">\n  <div class=\"tag\">{{tag}}</div>\n  <h1>{{title}}</h1>\n  <p>{{subtitle}}</p>\n</div>",
  "css": ".card { box-sizing: border-box; width: 1200px; height: 630px; padding: 80px; background: linear-gradient(135deg, #0f172a, #2563eb); color: #fff; font-family: Inter, sans-serif; display: flex; flex-direction: column; justify-content: center; }\n.tag { font-size: 28px; text-transform: uppercase; letter-spacing: 3px; opacity: .8; }\nh1 { font-size: 76px; margin: 24px 0; }\np { font-size: 34px; margin: 0; opacity: .9; }",
  "template": "custom",
  "variables": {
    "tag": "Release notes",
    "title": "Version 2.0 is here",
    "subtitle": "Faster renders, new templates, batch mode"
  },
  "format": "png",
  "deviceScaleFactor": 1,
  "quality": 90,
  "transparentBackground": false,
  "fullPage": false,
  "googleFonts": [
    "Inter:wght@400;700"
  ],
  "waitForFonts": true,
  "waitMs": 0,
  "pdfPaperFormat": "custom",
  "pdfLandscape": false,
  "escapeHtml": true,
  "maxConcurrency": 2
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `files` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "html": `<div class="card">
  <div class="tag">{{tag}}</div>
  <h1>{{title}}</h1>
  <p>{{subtitle}}</p>
</div>`,
    "css": `.card { box-sizing: border-box; width: 1200px; height: 630px; padding: 80px; background: linear-gradient(135deg, #0f172a, #2563eb); color: #fff; font-family: Inter, sans-serif; display: flex; flex-direction: column; justify-content: center; }
.tag { font-size: 28px; text-transform: uppercase; letter-spacing: 3px; opacity: .8; }
h1 { font-size: 76px; margin: 24px 0; }
p { font-size: 34px; margin: 0; opacity: .9; }`,
    "variables": {
        "tag": "Release notes",
        "title": "Version 2.0 is here",
        "subtitle": "Faster renders, new templates, batch mode"
    },
    "googleFonts": [
        "Inter:wght@400;700"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("forgeloop/html-to-image").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "html": """<div class=\"card\">
  <div class=\"tag\">{{tag}}</div>
  <h1>{{title}}</h1>
  <p>{{subtitle}}</p>
</div>""",
    "css": """.card { box-sizing: border-box; width: 1200px; height: 630px; padding: 80px; background: linear-gradient(135deg, #0f172a, #2563eb); color: #fff; font-family: Inter, sans-serif; display: flex; flex-direction: column; justify-content: center; }
.tag { font-size: 28px; text-transform: uppercase; letter-spacing: 3px; opacity: .8; }
h1 { font-size: 76px; margin: 24px 0; }
p { font-size: 34px; margin: 0; opacity: .9; }""",
    "variables": {
        "tag": "Release notes",
        "title": "Version 2.0 is here",
        "subtitle": "Faster renders, new templates, batch mode",
    },
    "googleFonts": ["Inter:wght@400;700"],
}

# Run the Actor and wait for it to finish
run = client.actor("forgeloop/html-to-image").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "html": "<div class=\\"card\\">\\n  <div class=\\"tag\\">{{tag}}</div>\\n  <h1>{{title}}</h1>\\n  <p>{{subtitle}}</p>\\n</div>",
  "css": ".card { box-sizing: border-box; width: 1200px; height: 630px; padding: 80px; background: linear-gradient(135deg, #0f172a, #2563eb); color: #fff; font-family: Inter, sans-serif; display: flex; flex-direction: column; justify-content: center; }\\n.tag { font-size: 28px; text-transform: uppercase; letter-spacing: 3px; opacity: .8; }\\nh1 { font-size: 76px; margin: 24px 0; }\\np { font-size: 34px; margin: 0; opacity: .9; }",
  "variables": {
    "tag": "Release notes",
    "title": "Version 2.0 is here",
    "subtitle": "Faster renders, new templates, batch mode"
  },
  "googleFonts": [
    "Inter:wght@400;700"
  ]
}' |
apify call forgeloop/html-to-image --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,forgeloop/html-to-image"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/akfTuuZrK2bJKYB80/builds/NSQTPdqvrbllcA5Wh/openapi.json
