Skip to content

HTML to image converter

Turn self-contained HTML and CSS snippets into PNG, JPG or WebP images without uploading code.

Live preview

Paste HTML and CSS below, load the sample card, or drop .html files to preview.

How to use HTML to image

  1. Enter your markup or add files. Paste HTML and inline style rules into HTML & CSS, select Load sample to inspect a metric card, or drop .html files up to 10 MB onto Drop .html files here.
  2. Select a responsive viewport width. Pick 375 for mobile cards, 800 for social graphics, 1200 for desktop layouts, or Custom to enter any width between 200 and 2400 px.
  3. Adjust Retina scale, padding, and backdrop. Choose 1x or 2x under Scale, set Padding (px) from 0 to 128, and pick White, Transparent, or Custom under Background.
  4. Inspect the live sanitized preview. Check computed pixel dimensions above Live preview and verify whether any external URLs were stripped for privacy.
  5. Export your image or batch archive. Select Copy PNG for instant clipboard pasting, or pick PNG, JPG, or WebP and select Save image to download a file or html-images.zip.

Everything runs in this browser tab. Nothing you paste or open is uploaded or logged, so it's safe for keys, tokens and private data.

Rendering self-contained HTML and CSS to PNG locally

Generating social preview cards, KPI badges, or invoice summary graphics usually forces teams to boot a headless Chromium container or send private markup to a screenshot API. This browser utility renders self-contained HTML and CSS into PNG, JPG, or WebP inside your current tab. Zero markup, class names, or embedded customer metrics ever touch a remote server.

Strict XHTML normalization inside SVG foreignObject

Under the W3C SVG 2 Embedded Content Specification, an SVG <foreignObject> container hosts an http://www.w3.org/1999/xhtml subtree inside a bounded vector viewport. Loose HTML5 habits such as unclosed <img>, <br>, or <hr> tags break strict XML parsing immediately.

To prevent syntax failures, the built-in tokenizer normalizes void elements, auto-closes implicit <p> or <li> siblings, and escapes stray ampersands before painting. When your source starts as prose or GFM tables rather than raw tags, turn Markdown & READMEs into crisp PNG or JPG cards instead.

Viewport presets, 2x Retina scale, and batch ZIP export

Testing responsive cards across screen breakpoints takes one click between 375, 800, 1200, or Custom (200 to 2400 px). Leave Scale on 2x to export crisp Retina graphics (1600 px wide for an 800 px card, plus outer padding).

Dropping two or more .html files (up to 10 MB each) opens a batch queue where you can click any filename to preview it. Selecting Save image renders every queued file with your active settings and packs them into html-images.zip.

When should you export HTML as PNG vs JPG or WebP?

Export HTML as PNG whenever your component relies on crisp UI typography, 1-pixel borders, or transparent rounded corners that paste cleanly into Figma, Slack, or slide decks. Choose WebP for lightweight web publishing with alpha transparency, or JPG when sharing opaque photographic banners where smaller byte size matters most.

Under the W3C PNG Third Edition Specification, truecolor-with-alpha PNG stores lossless 8-bit transparency without chroma subsampling artifacts around sharp text. If you need mathematical equations typeset with Computer Modern glyphs instead of manual HTML markup, try the formula to image tool.

Format Alpha transparency Compression mode Default quality Best HTML and CSS use case
PNG Full 8-bit alpha Lossless Deflate Lossless UI cards, badges, dark-mode stickers, crisp 1 px borders
WebP Full 8-bit alpha Lossy or lossless 0.92 Blog diagrams, lightweight docs, smaller transparent assets
JPG Opaque white or custom hex Lossy DCT 0.92 Photographic hero cards, newsletter banners without transparency
Copy PNG Full 8-bit alpha Lossless clipboard Lossless Direct pasting into Slack, Notion, Figma, or slides

Why are external stylesheets and remote images blocked?

All <script> tags, <iframe> elements, @import rules, and http:// or https:// subresource URLs are stripped before rendering so nothing leaves your browser and the 2D canvas stays origin-clean. Any external URL inside an SVG <foreignObject> taints the canvas and blocks pixel export.

Preventing canvas tainting and side-channel data leaks

Browser security models isolate <foreignObject> subtrees so malicious markup cannot probe cross-origin cookies, :visited link styles, or remote servers during rasterization. According to the MDN HTMLCanvasElement.toBlob() API Reference, calling toBlob() throws a SecurityError whenever a canvas has been tainted by cross-origin resources.

Because the sanitizer removes remote URLs, inline on* handlers, and javascript: links before building the SVG, your browser produces a clean PNG, JPG, or WebP blob every time. A status banner below Live preview reports the exact count of stripped external URLs whenever remote links were skipped.

Embedding inline SVG icons and Base64 data: URIs

Self-contained assets work offline without triggering network requests or canvas security blocks. You can inline <svg> icons directly in the markup, or encode local PNG, JPEG, GIF, WebP, or AVIF assets as data:image/* URIs inside img src or CSS url(...).

Before pasting large vector icons into your HTML snippet, shrink inline SVG icons before embedding to keep the payload compact. Custom typography works the same way when embedded as Base64 data:font/woff2 rules inside an inline <style> block.

CSS layout behavior, Shadow DOM sizing, and troubleshooting

Your browser’s native layout engine computes CSS Grid, Flexbox, custom properties, linear gradients, border-radius, and box-shadow directly at your chosen viewport width. Media queries respond immediately as you switch between 375 px, 800 px, and 1200 px presets.

Root selector rewriting and closed ShadowRoot measurement

Full HTML documents often attach background colors or typography rules to html or body selectors, which do not exist inside an SVG <foreignObject> <div> wrapper. The sanitizer automatically rewrites standalone html and body CSS preludes to .ht-html-root so page-level styles still apply.

Height calculation runs inside a hidden closed ShadowRoot using XML DOMParser before rasterization. As documented in the MDN Element.attachShadow() Documentation, closed Shadow DOM encapsulates layout measurement from host page styles without executing scripts.

Fixing clipped containers and missing web fonts

If an element overflows vertically or renders with unexpected system fonts, inspect Live preview before exporting. Check the computed pixel dimensions above the preview box (width×height px including 0 to 128 px padding at 1x or 2x scale) to confirm nothing is clipped.

Tip: Replace fixed height: 100vh rules with min-height or explicit pixel heights, and inline any CSS variables from external stylesheets so colors and spacing match your production build.

When you need selectable text, hyperlinks, or multi-page print pagination instead of a raster screenshot, switch to HTML to PDF.

Questions

Can I convert HTML to PNG with a transparent background?

Yes, select Transparent under Background and keep Format on PNG or WebP. Make sure your outer HTML wrapper or body rule does not declare an opaque background color. Rounded cards, badges, and CSS drop shadows then export with clean 8-bit alpha cutouts.

How do I include custom images or web fonts without external URLs?

Embed inline svg elements or encode local raster graphics as Base64 data:image/png or data:image/webp strings inside img src attributes. For custom typography, embed Base64 data:font/woff2 descriptors inside an inline @font-face rule so glyphs render offline.

Do CSS Grid, Flexbox, and custom properties work in the preview?

Yes, your browser layout engine computes CSS Grid, Flexbox, CSS variables, gradients, border-radius, and box-shadow rules directly. Media queries also respond immediately to whichever pixel width you select under Viewport width.

What happens when I drop multiple .html files at once?

Dropping two or more .html files switches the workspace into batch queue mode, where you can click any filename to inspect its live preview. Selecting Save image renders every queued file with your current settings and packs them into html-images.zip.

Why does my HTML snippet look slightly different from a live website?

Live pages often inherit reset rules, web fonts, and CSS variables from external stylesheet bundles that are skipped here for local privacy. Copy the computed CSS rules or inline style declarations into your snippet so colors, spacing, and fonts match.

Does JavaScript run inside pasted HTML before the image is saved?

No, all script tags, inline event handlers, javascript: links, and iframes are stripped before parsing, and height measurement uses XML DOMParser without script execution. Pasted markup must already contain the final static DOM structure you want to capture.

Updated