HTML to PNG Image Converter
Convert HTML code, files, or URLs to high-quality PNG images instantly in your browser. Adjust viewport, scale, and background settings.
About
Converting HTML to a raster image is a non-trivial rendering problem. Browsers parse HTML into a DOM tree, apply CSS cascade rules, compute layout geometry, composite layers, and rasterize pixels. Replicating that pipeline outside a browser historically required headless engines like PhantomJS or Puppeteer. This tool performs the entire conversion client-side by leveraging the browser's own rendering engine: your HTML is laid out in a sandboxed iframe at the specified viewport width W, then serialized into an SVG foreignObject, drawn onto a Canvas at scale factor s, and exported as a PNG blob. No server round-trip. No data leaves your machine.
Limitations exist. External resources (images, fonts, stylesheets from remote origins) will not render due to CORS restrictions unless they are inlined as base64 data URIs. JavaScript within the HTML is not executed. The output resolution in pixels equals W × H × s, where H is the computed document height. For production screenshots of live URLs with full JS execution, a server-side headless browser remains necessary. For static HTML, emails, templates, and CSS art, this tool produces pixel-accurate results.
Formulas
The output PNG dimensions are computed from the viewport width, the document's computed height, and the user-selected scale factor:
Where Wviewport is the simulated browser width in pixels, Hdocument is the rendered document scroll height, and s is the scale factor (1 = 96 DPI, 2 = 192 DPI).
The rendering pipeline follows this sequence:
The SVG wrapper encodes the HTML inside a foreignObject element with explicit width and height attributes matching the viewport. The canvas is sized to Wout × Hout and the context is scaled by s via drawImage stretching. Total pixel count must remain below the browser canvas limit of 268435456 pixels (163842).
Reference Data
| Parameter | Default | Range | Description |
|---|---|---|---|
| Viewport Width | 1024 px | 320 - 3840 | Simulated browser window width for layout computation |
| Scale Factor | 1× | 0.5 - 4 | Multiplier for output resolution (2× = Retina) |
| Background | transparent | Any CSS color | Canvas fill behind the HTML content |
| Output Format | PNG | PNG only | Lossless raster with alpha channel support |
| Max Canvas Area | 16384 × 16384 px | Browser limit; exceeding causes blank output | |
| foreignObject Support | All modern browsers | Chrome 4+, Firefox 3+, Safari 5+, Edge 12+ | |
| CORS Restriction | Same-origin only | External images/fonts must be base64-inlined | |
| Script Execution | FALSE | Sandboxed iframe blocks JS for security | |
| CSS Support | Full inline + <style> | External stylesheets must be inlined | |
| SVG in HTML | Supported | Inline SVG renders correctly | |
| Web Fonts | Base64 @font-face only | Remote font URLs blocked by CORS | |
| Typical Render Time | 200 - 1500 ms | Depends on DOM complexity and scale | |
| PNG Compression | Browser default | Canvas.toBlob uses deflate internally | |
| Color Space | sRGB | Standard color space for web content | |
| Alpha Channel | Preserved | Transparent background yields PNG with alpha | |