Skip to content
SnapDOMTry SnapStudioGitHub★ 8K
Library Comparison

SnapDOM vs html-to-image

Two libraries built on the same SVG foreignObject approach, compared on fidelity, fonts, Shadow DOM, plugins and developer experience.

TL;DR

html-to-image and SnapDOM both clone the DOM and render it through SVG foreignObject. SnapDOM adds a plugin pipeline, capture reuse in v3, and options for fonts, exclusions and output sizing.

SnapDOM vs html-to-image, head to head

Each library exports the same element to PNG five times. The average includes fresh and repeated calls; SnapDOM can reuse the unchanged capture. The gap depends on your hardware, content and capture pattern.

Test element to be captured by both libraries.
SnapDOM
Waiting to start…
html-to-image
Waiting to start…

A quick overview

html-to-image is a dom-to-image fork with TypeScript support. Its image helpers return data URLs, plus Canvas and Blob exports.

SnapDOM exposes capture and export lifecycle hooks. Official plugins, separate from the core exporters, add portable HTML, structured context and maps, searchable PDF, editable vector, GIF and video, plus filters, timestamps and text transformations.

Feature matrix

FeatureSnapDOMhtml-to-image
Pseudo-elements (::before / ::after)SupportedYes
Web fonts (@font-face)Embedded; local font optionEmbedded
Shadow DOMOpen rootsOpen roots
CSS variablesYesYes
CSS counter() / counters()YesDepends on the case
Line-clamp / multi-line ellipsisYesDepends on the case
Plugin systemYes (official + custom)No
Output formatsSVG · PNG · JPG · WebP · Canvas · BlobSVG · PNG · JPG · Canvas · Blob
PDF exportPluginNo
TypeScript typesBundledBundled
LicenseMITMIT

Support varies by fixture and rendering mode; test your own UI. Fixtures and loaded versions are in the live benchmark.

When to use which

Choose SnapDOM when…

  • You need fast captures, including repeats of the same element (live benchmark).
  • Your output depends on browser-rendered CSS, fonts or open Shadow DOM; test those elements in your target browsers.
  • You need PDF, editable vector, HTML or agent context, through plugins or your own.

Check before migrating…

  • Existing html-to-image post-processing needs adapting to SnapDOM's plugin lifecycle.
  • Test open Shadow DOM, CSS counters and line-clamp on the components you ship.
  • html-to-image has its own font embedding controls and canvas-based encoding; option semantics differ.

Same task, side by side

Capture #card as a PNG and add the image to the page:

html-to-image

import { toPng } from 'html-to-image';

const dataUrl = await toPng(document.querySelector('#card'));
const img = new Image();
img.src = dataUrl;
document.body.appendChild(img);

SnapDOM

import { snapdom } from '@zumer/snapdom';

const img = await snapdom.toPng(document.querySelector('#card'));
document.body.appendChild(img);

Migration snippet

html-to-imageSnapDOM
toPng(el)(await snapdom.toPng(el)).src
toJpeg(el, { quality: 0.9 })(await snapdom.toJpg(el, { quality: 0.9 })).src
toBlob(el)snapdom.toBlob(el, { format: 'png' })
toCanvas(el)snapdom.toCanvas(el)
toSvg(el)snapdom.toRaw(el)
{ backgroundColor: '#fff' }{ backgroundColor: '#fff' }
{ pixelRatio: 2 }{ dpr: 2 }
{ filter: keep }{ exclude: node => !keep(node), excludeMode: 'remove' }
{ fontEmbedCSS }No direct equivalent; embedFonts: 'auto' discovers used fonts
— (not supported){ plugins: [...] }
// Before
import { toPng } from 'html-to-image';
const dataUrl = await toPng(el, { pixelRatio: 2 });

// After
import { snapdom } from '@zumer/snapdom';
const img = await snapdom.toPng(el, { dpr: 2 });

Frequently asked questions

What is the difference between html-to-image and SnapDOM?

Both clone the DOM and render via foreignObject. SnapDOM adds capture lifecycle hooks, automatic reuse of eligible repeat captures, and official plugins for PDF, HTML, vector, GIF, video and agent context. Return types and options are in the migration table.

Does SnapDOM render web fonts better than html-to-image?

Both can embed @font-face declarations. SnapDOM 3 defaults to embedFonts: 'auto' for used web fonts and also has localFonts and excludeFonts. Check the exported text with your own font files and browser.

Can I add a watermark or filter without forking the library?

Yes. Use the colorTint, filter or timestampOverlay plugins, or write your own with two callbacks (afterClone / beforeExport). The plugins page has the full list.

How do I export to PDF?

Use the MIT pdf plugin. toPdf() returns a PDF Blob with selectable text, pagination and links. It ships on npm as @zumer/snapdom-pdf; the PDF reference covers installation and examples.

Try it here

Live element

Hard parts

transform + shadow

Result

Nothing captured yet

Edit the title, then run. This uses the real library from unpkg.