Screenshot a div in JavaScript
The shortest possible answer: pick the element, call SnapDOM, get an image. With a working example.
RecipeConvert HTML to PNG
Three patterns: append to the page, download to disk, or serialise to a Blob/Base64 for upload.
SVGConvert HTML to SVG
Export a self-contained SVG foreignObject capture and understand when it is native vector artwork and when it is not.
CanvasRender HTML to Canvas
Get an HTMLCanvasElement for compositing, pixel access or custom encoding.
ResolutionCapture in high resolution
Use DPR, scale and output dimensions without changing the live component.
Save a Chart.js chart as a PNG
Export the chart with its title, legend and container, not just the bare canvas. Includes the timing gotcha.
DashboardExport a dashboard as an image
Capture charts, KPI cards, legends and surrounding UI in one sharp export.
ReactExport a React component
Use a ref to save a rendered component as PNG, SVG or Canvas.
ChartsExport a chart as SVG or PNG
Include HTML titles, legends and annotations around canvas or SVG charts.
DocumentsExport an invoice or report
Create a crisp snapshot of an invoice, receipt, certificate or browser report.
SocialGenerate a social card
Design with HTML and CSS, then export a browser-rendered Open Graph image.
PDF workflowCapture before creating a PDF
Flatten a visual component before passing it to a single-page PDF workflow.
Capture without Puppeteer
Export an existing browser element without operating a Chromium service.
Web ComponentsCapture Shadow DOM
Capture accessible open shadow roots and their resolved styles.
IframeCapture an iframe
Include same-origin frame content and account for cross-origin restrictions.
Full pageCapture a full web page
Snapshot the document layout beyond the visible viewport.
TestingCapture for visual regression
Stabilize component state and produce input for a baseline diff workflow.
About these recipes
Each how-to answers exactly one question with the minimum amount of code. They're meant to be skimmed: you find the recipe, copy it, paste it, done. If you want a deeper walkthrough for a specific framework, see the framework guides instead.
Request a recipe
Open an issue on GitHub describing the task and we'll add it.
Request a recipe Open the demo