HTML Parameter

The html parameter is required for the HTML/CSS API and accepts any valid HTML content.

Specifications

PropertyValue
Typestring
RequiredYes
DefaultNone
APIHTML/CSS API only

Description

The HTML content you want to convert to an image. This can include:

  • Plain HTML
  • Inline CSS
  • Inline JavaScript
  • External resources (images, fonts, etc.)

Examples

Basic HTML

{
    "html": "<h1>Hello World</h1>"
}

Response:

{
    "success": true,
    "credits_remaining": 95,
    "id": "abc123",
    "url": "https://i.html2img.com/abc123.png"
}

HTML with Inline Styles

{
    "html": "<div style='background: #f0f0f0; padding: 20px;'><h1 style='color: blue;'>Styled Content</h1></div>"
}

HTML with External Resources

{
    "html": "<div><img src='https://example.com/image.jpg'><h1>Image with Text</h1></div>"
}

External resources must be publicly accessible. The API downloads them server-side and includes them in the rendered image.

Common values

  • Plain HTML with inline styles. <div style="background:#0F766E;color:white;padding:40px;">Coastline Coffee Co</div> works as a starting payload.
  • Linked Google Fonts. Include <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet"> in <head> to use Inter.
  • Self-hosted @font-face. Reference a public URL in your CSS so the font loads server-side.
  • Charts and dynamic content. Inject a chart library via <script src> and call its render function inline. See the JavaScript guide for the 30 second budget.

When to use

Use the html parameter whenever you want full design control. The HTML and CSS endpoint runs your inline JavaScript, which makes it the right choice for any render that needs to compute or transform data at request time.

Common mistakes

  • Forgetting to escape JSON. Pass the HTML as a JSON string, with quotes escaped. Multi-line markup needs \n rather than literal newlines.
  • Pointing at private resources. Localhost URLs and intranet hosts will not load. Host fonts and images on a public URL.
  • Skipping wait_for_selector. If your render depends on a script that runs after page load, the API may capture before it finishes. See wait_for_selector.

See also: chart-screenshot example, invoice-receipt example, getting started guide.