Skip to content
HTML to Image & Video

html2canvas vs html-to-image vs modern-screenshot

Three popular libraries turn a DOM node into an image. They work in two very different ways, and that difference decides which one fits your project.

Updated · 5 min read

If you search for a way to turn HTML into an image in the browser, three names keep appearing: html2canvas, html-to-image and modern-screenshot. They all return a PNG, JPEG or canvas from a DOM node, but they do it differently, so results and failure modes differ.

Two ways to render

Re-drawing the page: html2canvas

html2canvas walks the DOM, reads computed styles, and paints elements onto a canvas using its own rendering code. It does not need SVG foreignObject. The tradeoff is that it must re-implement browser layout and painting, so some newer or complex CSS can render differently from the live page.

Letting the browser render: html-to-image and modern-screenshot

These two clone the node, inline the styles and resources it needs, serialize it into an SVG foreignObject, and draw that onto a canvas. The browser does the actual layout and painting, so modern CSS usually matches the page closely. modern-screenshot started as a fork of html-to-image and adds options for things such as web workers, fetch behavior and placeholder images when an asset fails to load.

What this means in practice

  • Fidelity: the foreignObject libraries tend to match modern CSS more closely, while html2canvas can miss features.
  • Assets: the foreignObject libraries must fetch and inline fonts and images, so cross-origin resources matter a lot.
  • Browser quirks: Safari and Firefox have had foreignObject edge cases, and the libraries add workarounds for them.
  • Control: modern-screenshot exposes more tuning, such as a custom fetch placeholder, which makes it easier to detect and report failed images.

How to choose

Pick by testing your own layout, not by reading feature lists. Take the most complex component you have, export it with each library, and compare the result with the live page at 1x and 2x scale. Check fonts, gradients, shadows, border radius, clipped content and any images from other domains.

This site uses modern-screenshot because it renders through the browser engine, handles transparency cleanly, and lets us detect images that fail to load so we can warn you instead of silently exporting a blank area.

See the result with your own HTML

Open HTML to PNG

More guides