HTML TO IMAGE

Render hosted HTML into a production-ready image

Publish the HTML at an HTTP or HTTPS URL, send that URL to Snapshot Site, and receive a browser-rendered PNG, JPEG, or WebP. Control responsive width, full-page capture, rendering delay, cookie banners, and page cleanup without operating Chromium yourself.

HTTP(S)
Hosted page input
3 image formats
PNG, JPEG, WebP
Real browser
CSS and JavaScript rendered
Install:curl -X POST https://api.prod.ss.snapshot-site.com/api/v1/screenshot
Auth:x-snapshotsiteapi-key: YOUR_API_KEY
Get started for free
HTML render output
Hosted HTML flowing through a browser renderer into a finished image asset
Good fits
Social cards and shareable page previews
Template previews generated by backend systems
Documentation and changelog screenshots
Visual QA for server-rendered or client-rendered pages

HTML-to-image starts with a reachable page

Snapshot Site captures URLs rather than accepting an arbitrary raw HTML string. Host or preview the document first, then capture that controlled URL. This boundary keeps relative assets, fonts, scripts, and security policy attached to a real origin.

1

Serve the document

Expose the template through a public or otherwise reachable HTTP(S) URL with its styles, fonts, and images available.

2

Choose the viewport

Width and height determine responsive layout; fullSize decides whether the result stops at the viewport or includes the scrollable document.

3

Wait for the intended state

Use a measured delay when hydration, charts, fonts, or asynchronous data need time after navigation.

4

Store the returned asset

Persist the returned link or download the file into the storage system that owns the final preview or report.

Quick start

Capture a hosted template

1

Publish the HTML and its assets at a stable preview URL

2

POST that URL with an explicit width and image format

3

Add fullSize, hideCookie, or delay only when the page requires them

4

Check the response and save the returned image

HTML-to-image API example

cURL

Render a hosted HTML template as WebP

Capture a preview route after its client-side template has settled. The API key stays in a server-side environment.

curl --request POST \
  --url https://api.prod.ss.snapshot-site.com/api/v1/screenshot \
  --header 'Content-Type: application/json' \
  --header 'x-snapshotsiteapi-key: YOUR_API_KEY' \
  --data '{
    "url": "https://preview.example.com/cards/release-42",
    "format": "webp",
    "width": 1200,
    "height": 630,
    "fullSize": false,
    "hideCookie": true,
    "delay": 2
  }'

What an HTML to image API actually needs to solve

Generating an image from HTML sounds like a format conversion, but the difficult part is not encoding pixels. It is reproducing the browser state that turns markup, CSS, fonts, images, and JavaScript into a stable layout. A raw document may reference relative assets, depend on an origin, fetch data after hydration, or change at responsive breakpoints. A reliable workflow therefore begins with a real page rather than an isolated string.

Snapshot Site accepts an HTTP or HTTPS URL. If your application starts with an HTML template, publish that template through a controlled preview route first. The route can be part of the same application that produces invoices, release cards, reports, or documentation. Once the page is reachable, the screenshot request records the rendered result.

This approach is deliberately narrower than services that accept arbitrary HTML in the request body. It is a good fit when your templates already have a preview URL or when rendering them inside their real application origin is important. If direct raw-HTML input is a hard requirement, verify that requirement before choosing the integration.

Build a reproducible rendering pipeline

Give each document a stable preview URL

Use a route that identifies the exact template and data revision, such as /previews/release/42. Avoid a generic preview whose output depends on a mutable session or the latest database row. A stable URL makes failures repeatable and gives reviewers a page they can open in a normal browser.

The route should not expose unrelated customer data. Generate only the document needed for the capture, use synthetic or approved values during testing, and expire temporary routes when they are no longer useful.

Control the responsive layout explicitly

The viewport width is part of the input. A 390-pixel preview can activate mobile navigation and stacked cards, while a 1200-pixel preview may produce a desktop composition. Do not capture at one width and resize later if the page is responsive; resizing pixels cannot reproduce a different CSS layout.

For fixed social cards, set both width and height and keep fullSize false. For long release notes or reports, set the intended width and use fullSize: true. Keep these options next to the template revision in your job payload so a later worker does not guess them.

Wait for a page signal, not an arbitrary long delay

The API exposes a bounded delay for pages that settle after navigation. Use the smallest value that consistently covers the real rendering work. A long delay hides weak page-state design, increases job time, and still cannot guarantee that a third-party widget has finished.

Where you control the preview application, make the route deterministic: preload required data on the server, avoid animations, use stable fonts, and remove live timestamps. A two-second delay can help with hydration; it should not be the mechanism that decides which content appears.

Common HTML-to-image use cases

Social and campaign previews

Marketing systems often already render an HTML preview for an announcement, article, or campaign. Capture that route at the exact card dimensions and store the returned WebP or PNG alongside the content revision. This keeps typography and brand components in the same web design system used elsewhere.

Documentation and product releases

Documentation teams can create an image from a hosted demo state after each meaningful UI change. The result can be attached to a changelog, embedded in a knowledge base, or reviewed before publication. Link the capture to the source revision so it can be regenerated deliberately.

Report and dashboard snapshots

For a shareable image, render an approved report route at a desktop width and hide controls that are meaningful only in the interactive application. For document delivery, the PDF Generation API is usually a better target because pagination and document handling matter more than image dimensions.

Visual review before publishing

Capture a draft template and compare it with an approved baseline using the Visual Diff API. This catches visual changes that a string comparison misses, including a missing stylesheet, a shifted component, or a font fallback.

Reliability, security, and performance

Keep the API key in the backend, worker, CI secret store, or scheduler. Do not put it in the generated HTML or client-side fetch code. Treat preview URLs as data access surfaces: authorize them when possible, avoid embedding permanent credentials, and make temporary links expire.

Limit capture jobs to known URLs created by your application. If users can submit arbitrary targets, validate schemes and destinations before passing them to any rendering service. Log the template identifier and capture options without logging sensitive query values.

Finally, avoid generating the same image on every page view. Capture when the underlying template or data changes, store the asset, and serve the stored file. This reduces latency for end users and makes the visible image correspond to a known content revision.

HTML to image checklist

  1. Host the exact document at a stable HTTP(S) URL.
  2. Confirm every asset loads from the rendering environment.
  3. Choose width, height, format, and full-page behavior deliberately.
  4. Remove animations, timestamps, and transient overlays where possible.
  5. Keep the API key server-side.
  6. Validate the response before saving or publishing the image.
  7. Cache the asset by template and data revision.
  8. Compare important templates against approved baselines when visual accuracy matters.

HTML to image API FAQ

Can I send a raw HTML string directly to Snapshot Site?

No. The screenshot endpoints require an HTTP or HTTPS URL. Publish the document on a preview route or temporary hosted page, then capture that URL.

Does the API render JavaScript inside the hosted page?

Yes. The page is opened in a real browser. Add a small, evidence-based delay when client-side rendering or asynchronous data completes after navigation.

Which image formats can I generate?

Use PNG for lossless interface detail, JPEG for compact photographic previews, or WebP for a modern balance between image quality and file size.

How do relative CSS, fonts, and images work?

They resolve against the hosted page origin as they would in a normal browser. Make sure the preview route can load every required asset without a private local path.

Can I capture only the initial viewport?

Yes. Set width and height and leave fullSize false. Use fullSize true only when the complete scrollable document is the intended output.

How should I protect a private preview route?

Prefer a short-lived, unguessable preview URL that exposes only the required document. Never place the Snapshot Site API key in browser JavaScript or in the preview URL.

Why is the output different between two runs?

Fonts, animations, rotating content, late network responses, consent state, and viewport changes can alter pixels. Fix the inputs and remove known dynamic regions.

Is this the same as extracting rendered HTML?

No. HTML-to-image produces a visual asset from a hosted document. Rendered-HTML extraction and visual capture solve different downstream problems.

Render your first hosted template

Use one representative template, fix its viewport and timing, then test the output before expanding the workflow to a template library.