1. Home
  2. Developer
  3. HTML to Image

HTML to Image

Paste HTML and CSS and save it as a PNG image.

Runs in your browser · No upload
Your HTML is placed in an SVG foreignObject, loaded as an image and drawn to a canvas to save as PNG. Scripts do not run inside an image, and external resources (link stylesheets, http image URLs, @import, url()) are blocked, so only inline CSS and data: images (Base64) are drawn.
px
100~4,000
Export scale
Height
.png

The image reads your markup as XML. Turn this off to convert the text as written and be told about each error.

Auto-fixed: closed empty tags 1, named entities to numeric 2
HTML preview
Preparing the preview…
How it looks in an isolated (sandboxed) frame. Scripts and external requests are blocked. Auto height is measured in this frame.
PNG result
Creating the image…
Image size
800 × 600 px
Export size
1,600 × 1,200 px
Auto height
-

Your HTML and CSS are processed in this browser only and never sent to a server.

How to use

  1. Paste the markup you want to turn into an image into the HTML box. Put styles in a <style> element there or in the CSS box below. It starts with a sample.
  2. Choose the width and the export scale (1x, 2x or 3x), and pick a background: transparent, white or a custom #rrggbb color.
  3. Height is Auto by default. The preview frame measures the content height and the image uses it. Switch to Manual when you need an exact size.
  4. When the result looks right, press Download PNG or Copy image. If your browser blocks saving the PNG, use Save as SVG instead.

How the image is made

Your HTML is placed inside an SVG foreignObject, loaded as an <img>, drawn onto a canvas and saved as a PNG. There is no server and no separate rendering engine: the browser draws it itself, so fonts and layout match the browser you are using right now.

An SVG loaded through <img> does not run scripts and does not fetch external addresses. Anything drawn by a <script> will not appear, and the following are not reflected in the image.

Blocked Example Use instead
External stylesheets <link rel="stylesheet" href="...">, @import paste the same CSS into <style> or the CSS box
External images <img src="https://...">, url(https://...) a data:image/png;base64,... data URI
Web fonts a Google Fonts link a font installed on the system
Dynamic elements <canvas>, <video>, <iframe>, scripts static HTML and CSS only

When your input contains such addresses, a table lists them with line numbers. Relative paths such as photo.jpg cannot load either, so they count too. References that point inside the document, such as url(#id), keep working.

XML rules and auto-fix

Content inside a foreignObject is read as XML, not HTML. A single missing end tag stops the whole image, so the auto-fix option, which is on by default, repairs what can be repaired safely.

Input After fixing
<br>, <img src="..."> <br/>, <img src="..."/>
&nbsp;, &copy; &#160;, &#169;
<input disabled> <input disabled=""/>
<a href=x?a=1&b=2> <a href="x?a=1&amp;b=2">
<DIV> <div>
<svg> without xmlns SVG namespace added
<!DOCTYPE html> removed
& or < inside <style> wrapped in CDATA

Errors that cannot be repaired are reported with line:column positions, and no image is made. These are unclosed tags (especially <li>, <p> and <td>), end tags with no opening tag, duplicate attributes on one tag, entities XML does not define, and undeclared prefixes such as <o:p>. With auto-fix off, the rows in the table above are reported as errors too, which is useful when you want to convert the text exactly as written.

Size and scale

Item Range
Width 100 to 4,000 px
Height Auto, or 20 to 20,000 px
Scale 1x, 2x, 3x

The export size is width x scale by height x scale. For example, 800 x 600 at 2x gives a 1,600 x 1,200 px image. When the result would exceed what a canvas can draw (36 million pixels in total, 16,000 px per side), the scale is lowered automatically, and 4,000 x 3,000 can only be exported at 1x.

The outer element is a <body>, so body { ... } rules in your CSS apply as expected. html { ... } rules do not.

Frequently asked questions

My external image does not show up in the PNG.

The browser blocks external addresses inside an image. Convert the picture to Base64 and use <img src="data:image/png;base64,..."> instead. Image to Base64 can do the conversion.

The preview and the PNG look slightly different.

The preview frame is a normal HTML document, while the PNG is a foreignObject read as XML. Differences can appear with html selectors, with unclosed tags that the browser would repair for you, and with the default look of form controls. The PNG result panel shows what will actually be saved.

Saving fails in Safari.

Some Safari versions refuse to export a canvas that holds a foreignObject image. Use Save as SVG, or try another browser.

I want an image of source code.

For a syntax-highlighted code card, Code to Image is more convenient. This tool fits when you have written an HTML layout and want it as it is.

Related tools: Code to Image, Screenshot Beautifier, SVG to PNG, HTML CSS JS Playground, HTML Validator, HTML Beautifier & Minifier.

Your HTML and CSS are processed in this browser and never sent to a server.

Can't find the tool you need?

Tell us what you want to do. We build the most requested tools first.