How to convert HTML to SVG
Capture a DOM element as a scalable, self-contained SVG image without a server or headless browser.
Use snapdom.toSvg(element) for an SVG image, or snapdom.toRaw(element) when you need the SVG data URL.
Export the element as SVG
Install @zumer/snapdom, select the rendered element, and capture it:
import { snapdom } from '@zumer/snapdom'
const element = document.querySelector('#card')
const svg = await snapdom.toSvg(element, { embedFonts: true })
document.body.appendChild(svg)The SVG wraps the rendered HTML
SnapDOM clones the selected DOM subtree, inlines its rendered styles and assets, then serializes it inside SVG <foreignObject>. The browser remains responsible for painting the HTML.
Use toRaw() when you need the underlying data URL for storage or transport.
Try HTML SVG live
Capture this styled HTML card as an SVG image. The result stays sharp when resized.
HTML stays HTML
The result stays sharp at any size.
Limits and common mistakes
The output is an SVG container around styled HTML; it is not a conversion to SVG paths. Use it for browser display. For editable SVG geometry in Figma or Illustrator, use the Vector plugin; embedded images and canvas content remain raster.
Frequently asked questions
Is the result true vector artwork?
Not with toSvg(): text and HTML stay inside SVG foreignObject. For real paths editable in Figma or Illustrator, use the Vector plugin.
Can I get the SVG source?
Use snapdom.toRaw(element) to get the SVG data URL, or fetch and decode that URL when XML text is required.