SnapDOM vs html2canvas
DOM-to-canvas vs SVG-based capture: output types, font handling and the options you need to migrate.
html2canvas paints the DOM onto Canvas with its own JavaScript renderer. SnapDOM renders a styled clone through SVG, exports images or Canvas, and has a plugin lifecycle. Both are MIT-licensed and run in the browser.
SnapDOM vs html2canvas, head to head
Each library captures the same element 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.
A quick overview
html2canvas paints the DOM onto a <canvas> with a renderer that implements CSS itself, so supported properties and output can differ from the browser's.
SnapDOM clones the DOM, inlines styles, accessible fonts and images, and wraps the clone in an SVG <foreignObject>. The browser paints it, within resource-access limits.
Feature matrix
| Feature | SnapDOM | html2canvas |
|---|---|---|
Pseudo-elements (::before / ::after) | Supported | Passes tested fixture |
Web fonts (@font-face) | Embedded | Best-effort |
| Shadow DOM | Open roots | Passes tested fixture |
| CSS variables | Yes | Partial |
CSS counter() / counters() | Yes | Depends on the case |
Same-origin <iframe> capture | Yes | Limited |
| Line-clamp / multi-line ellipsis | Yes | Depends on the case |
| Plugin system | Yes | No |
| Output formats | SVG · PNG · JPG · WebP · Canvas · Blob | PNG, JPG (via canvas.toDataURL) |
| Runtime dependencies | 0 | 0 |
| Approach | Clone + foreignObject (browser renders) | Re-implements CSS painter |
| License | MIT | MIT |
Support varies by fixture and rendering mode; test your own UI. Fixtures and loaded versions are in the live benchmark.
Run the live comparison on your hardware, then test your own elements. This fixture does not establish a performance result for every page.
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.
Keep html2canvas when…
- Your captures already meet your requirements and migration has no measured benefit.
Check the issue tracker for known problems with your content, then compare output from both.
Same task, side by side
Capture #card as a PNG and add the image to the page:
html2canvas
import html2canvas from 'html2canvas'; const canvas = await html2canvas(document.querySelector('#card')); const img = new Image(); img.src = canvas.toDataURL('image/png'); document.body.appendChild(img);
SnapDOM
import { snapdom } from '@zumer/snapdom'; const img = await snapdom.toPng(document.querySelector('#card')); document.body.appendChild(img);
SnapDOM returns the HTMLImageElement ready to append, with no toDataURL call. For a canvas, use snapdom.toCanvas(el).
Migration notes
Return types and option meanings differ. These equivalents keep the same output format:
| html2canvas | SnapDOM |
|---|---|
| html2canvas(el) | snapdom.toCanvas(el) |
| canvas.toDataURL('image/png') | (await snapdom.toPng(el)).src |
| canvas.toDataURL('image/jpeg', 0.9) | (await snapdom.toJpg(el, { quality: 0.9 })).src |
| canvas.toBlob(cb, 'image/png') | await snapdom.toBlob(el, { format: 'png' }) |
| { scale: 2 } | { dpr: 2 } |
| { backgroundColor: '#fff' } | { backgroundColor: '#fff' } |
| { ignoreElements: skip } | { exclude: skip, excludeMode: 'remove' } |
| — (not supported) | { embedFonts: true } |
For a Canvas consumer, start here and compare the output:
// Before import html2canvas from 'html2canvas'; const canvas = await html2canvas(el, { scale: 2 }); // After import { snapdom } from '@zumer/snapdom'; const canvas = await snapdom.toCanvas(el, { dpr: 2 });
The full option map, the onclone replacement and the mistakes people make after switching are in the migration guide.
Frequently asked questions
Why does html2canvas not render my Shadow DOM?
It depends on the implementation. SnapDOM walks open Shadow roots, copies resolved styles and renders the clone through SVG <foreignObject>. Closed roots are not reachable through the standard DOM API.
html2canvas doesn't render web fonts correctly, what do I use?
First make sure fonts load before capture. SnapDOM 3 uses embedFonts: 'auto' by default to embed used web fonts in the SVG. Font files must be accessible to the page; test the image in your target browser.
html2canvas is slow on large DOMs, is there a faster alternative?
SnapDOM uses a different rendering path and v3 can reuse eligible captures. The gain depends on the DOM, assets and capture pattern. Compare your own elements in the live benchmark above.
Is html2canvas still maintained in 2026?
This page compares html2canvas 1.4.1. For current status, check its releases and issue tracker. A release date alone does not say whether a library meets your needs.