Screenshot any HTML element in the browser
Turn any part of a web page into a PNG, JPEG, WebP, SVG or canvas, right in the visitor's browser.
A faster, more accurate html2canvas alternative with a compatible API. No server, no dependencies.
PNG · JPEG · WebP · SVG · html2canvas API · web fonts · shadow DOM · Chrome, Safari, Firefox
html2shot
Screenshot any element to an image. The browser does the drawing, so modern CSS, web fonts, SVG, shadow DOM and form values come out right. It had the best score of six libraries in Chrome, Safari and Firefox in our benchmark, and works as a drop-in replacement for html2canvas.
toimage
Turn an SVG, canvas, <img>, video, Blob or URL into a PNG, JPEG or WebP at any size, sharp, in one call. With html2shot it does HTML elements too.
| You want | Code |
|---|---|
| Install | npm install html2shot |
| A PNG of an element | await toPng(element) |
| A sharper image | await toPng(element, { scale: 2 }) |
| A file to upload or copy to the clipboard | await toBlob(element) |
| Replace html2canvas | import html2canvas from 'html2shot' |
| No build step | <script src="https://cdn.jsdelivr.net/npm/html2shot@1"></script> |
Found a page that renders wrong? Report it with a small HTML snippet, the browser, and a screenshot of the page and of html2shot's output. Speed-ups and framework recipes are welcome too, see CONTRIBUTING.md.
html2shot is free and always will be. ⭐ Star the repo to follow new releases, or become a sponsor to keep screenshots accurate as browsers change.
Code: MIT