Skip to content
UniKit

HTML to image (capture prep)

Prepare a capture: sanitized HTML, an export height estimated from the content line count, and a full document string carrying the background colour and viewport width. No bitmap is drawn here, the PNG comes from the page canvas, and this step only covers preparation and sizing.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

HTML source

Result

The result can be copied directly.

Paste HTML to see the capture sizing

Characters: 0 · Lines: 0 · Export width: 0 · Export height: 0

What this tool does

  • Confirm the export size before capturing so long pages are not clipped.
  • Get sanitized HTML plus a document string to feed a canvas export.
  • Normalise the background colour so transparent areas do not turn black in PNG.

Example

Input

<h1>Title</h1><p>Body text</p>

Output

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HTML to image</title>
<style>html,body{margin:0;background:#ffffff}body{width:1200px;padding:16px;box-sizing:border-box}</style>
</head>
<body>
<h1>Title</h1><p>Body text</p>
</body>
</html>

Only sanitising, sizing and document assembly happen here; the PNG is drawn by the page canvas.

Frequently asked questions

Does it produce a PNG?

No. It sanitizes, estimates sizes and emits a document string; the bitmap is drawn by the page canvas and nothing pretends otherwise.

How is the height estimated?

Block elements and text lines are folded into print lines, multiplied by a 24px line height plus 64px padding, with a 200px floor. The real height depends on fonts and CSS.

What are the width limits?

The width must be within 120–10000px or `invalid-width` is thrown; the only strategies are device width and content width.

Why white by default?

Transparent backgrounds usually export as black in PNG, so `#ffffff` matches what you see; a three-digit value such as `#eee` also works.

Keywords:html2imgcanvasscreenshotdeveloper

Related tools