Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To export a rendered HTML element such as a div, card, chart, or dashboard panel to PNG, select the node, render it with a DOM-to-image library, encode the resulting canvas with HTMLCanvasElement.toBlob(), and download the Blob with an object URL. The result is usually a reconstruction of the DOM, not a literal browser screenshot, so test the exact element, assets, CSS, and browsers your application supports.

The basic export pipeline

A reliable client-side export has five stages:

  1. Find the target node with document.querySelector() or another DOM lookup.
  2. Render that node with a library such as html2canvas or html-to-image.
  3. Encode the canvas as a PNG Blob with toBlob().
  4. Create a temporary object URL and an anchor with a useful filename.
  5. Start the download, then revoke the object URL after the browser has begun using it.

Do not assume that “screenshot” means pixel-for-pixel browser output. The html2canvas documentation explains that its image is built from DOM and style information rather than captured as an actual screenshot, and unsupported CSS can differ or be omitted.

Working example with html2canvas

Install the package in an application that uses a JavaScript bundler:

npm install html2canvas

Give the element a stable selector and call an asynchronous export function:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty
import html2canvas from 'html2canvas';

async function exportElementAsPng() {
  const element = document.querySelector('#capture');
  if (!element) {
    throw new Error('Capture element not found');
  }

  const canvas = await html2canvas(element, {
    backgroundColor: '#ffffff',
    scale: window.devicePixelRatio || 1
  });

  const blob = await new Promise((resolve) => {
    canvas.toBlob(resolve, 'image/png');
  });

  if (!blob) {
    throw new Error('PNG encoding failed');
  }

  const url = URL.createObjectURL(blob);
  const link = document.createElement('a');
  link.href = url;
  link.download = 'dashboard-panel.png';
  document.body.appendChild(link);
  link.click();
  link.remove();

  // Delay revocation so the download has a chance to start.
  setTimeout(() => URL.revokeObjectURL(url), 1000);
}

document.querySelector('#download-png')?.addEventListener('click', () => {
  exportElementAsPng().catch((error) => {
    console.error(error);
    alert(`Could not export the element: ${error.message}`);
  });
});

toBlob() produces a binary Blob suitable for a download. According to MDN’s toBlob() documentation, PNG is the default when the requested type is omitted or unsupported; the callback can receive null, so the example checks it. A canvas that is not origin-clean can also cause a security exception when encoded.

Minimal HTML to try it

<button id="download-png" type="button">Download PNG</button>
<div id="capture" style="width:420px;padding:24px;background:#f5f7fb;border:1px solid #d9deea;border-radius:12px">
  <h2>Monthly sign-ups</h2>
  <p style="font-size:32px;margin:0">12,480</p>
</div>

Wait until fonts, images, charts, and data have finished rendering before calling the function. If your framework updates the element after a state change, export after the next paint (for example, inside a browser-side event handler after the visual update).

Using html-to-image instead

html-to-image provides toPng(), toBlob(), and SVG/canvas output options. It clones the DOM, copies styles, embeds fonts and images where possible, wraps the clone in SVG foreignObject, and rasterizes it. A PNG export can be as short as:

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

async function downloadCard() {
  const node = document.querySelector('.report-card');
  if (!node) throw new Error('Report card not found');

  const dataUrl = await toPng(node, {
    cacheBust: true,
    pixelRatio: 2,
    backgroundColor: '#ffffff'
  });

  const link = document.createElement('a');
  link.download = 'report-card.png';
  link.href = dataUrl;
  link.click();
}

This API returns a data URL, which is convenient for a small image but keeps the complete encoded image in memory. For larger exports, prefer its toBlob() function or another Blob-based path. The project notes possible failure with very large DOM trees or data URLs, and browser support for SVG foreignObject matters.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choosing a renderer

Option Output and workflow Where it fits Important limits
html2canvas Resolves to a canvas that you encode with toBlob(). Direct, familiar element rendering when its supported CSS matches your design. Reconstructs the view; unsupported CSS, cross-origin images, and cross-origin iframes can prevent an accurate result. See the documentation.
html-to-image Offers toPng, toBlob, SVG, and canvas methods. Cases where its style, font, and image embedding approach produces the desired output. Large DOM/data URLs and browser foreignObject support can be problematic; test your target.
Element Capture API A selected screen-capture track is restricted to an element, then a frame is drawn to a canvas. Native capture experiments in browsers that implement both Element Capture and ImageCapture.grabFrame(). Requires screen-capture flow and specific browser support; it is not a universal drop-in replacement. See MDN’s Element and Region Capture guide.

Compare the actual CSS properties in the element, web-font loading, image origins, browser coverage, dimensions, and whether you need a PNG, SVG, or Blob. No library can promise pixel-perfect output without testing those conditions.

Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]

Images, fonts, and cross-origin security

Cross-origin images

An image hosted on another origin must grant CORS permission for safe canvas export. The image server needs an appropriate Access-Control-Allow-Origin response, and your image request must be made in a CORS-compatible way. The MDN CORS-enabled image guide explains the required relationship between the image request and server headers. Setting a library option cannot override browser security policy.

If a remote image taints the canvas, encoding may throw SecurityError or return no Blob. Proxy the asset through an origin you control, configure the image host’s CORS policy, or omit/replace the asset for the export. Do not use a proxy that exposes private content without authentication and access controls.

Cross-origin iframes

html2canvas cannot inspect the document inside a cross-origin iframe. You can capture a same-origin frame under the normal DOM rules, ask the framed application to export itself, or use a server/browser capture that loads the complete page. You cannot bypass the same-origin policy from client JavaScript.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fonts and visual readiness

Wait for web fonts before rendering when typography matters:

await document.fonts.ready;
const node = document.querySelector('#capture');
// Render node only after the fonts and its data-dependent content are visible.

For images, wait for the image load event or check that application data and chart animations have completed. Freeze animations and transitions with a temporary export class if a moving chart or blinking cursor causes inconsistent frames.

Rank #3
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers

Quality, dimensions, and memory

Pixel density

The scale option in html2canvas or pixelRatio in html-to-image controls output density. A value around the device pixel ratio makes text sharper on high-density displays, but it multiplies pixel count and memory use. Choose a deliberate scale for your required print or display size instead of always choosing the largest number.

Large elements

Browser canvas dimensions have implementation-dependent limits. MDN’s canvas reference notes that maximum size depends on the browser and environment. A very tall dashboard can fail, produce a blank result, or exhaust memory. Split it into sections, reduce scale, remove off-screen content, or export on a server.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Blob versus data URL

MDN recommends toBlob() for most download workflows because toDataURL() turns the entire image into an in-memory string. Keep a data URL for small previews or APIs that specifically require one; use a Blob and object URL for a file download.

Controlling what gets exported

Use a dedicated wrapper rather than the entire page. Hide buttons, menus, focus rings, and other controls with an export-only class:

.exporting .no-export { display: none !important; }
.exporting { color-scheme: light; }
const node = document.querySelector('#capture');
node.classList.add('exporting');
try {
  // call html2canvas(node) or toPng(node) here
} finally {
  node.classList.remove('exporting');
}

Set an explicit background when the design relies on transparency or inherited page colors. If the element uses CSS variables, pseudo-elements, filters, or blend modes, verify the output in every supported browser; reconstruction engines may implement these differently.

Rank #4
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.

Troubleshooting common failures

Symptom Likely cause Fix
“Capture element not found” The selector is wrong, the component has not mounted, or the code ran before the DOM existed. Use a stable ID/class, run after mount, and check the node before rendering.
Blank or partially blank image Images/fonts/data were not ready, the canvas exceeded a browser limit, or a resource was blocked. Wait for readiness, lower scale, split the capture, and inspect network and console errors.
SecurityError during encoding A cross-origin image tainted the canvas. Enable CORS on the image host, serve the asset from your origin, proxy it safely, or remove it.
Iframe content is missing The iframe is cross-origin. Export inside the framed app, make it same-origin where appropriate, or use a page-level capture service.
Text or CSS differs The library reconstructs DOM/styles and does not support every CSS feature. Simplify export styles, wait for fonts, compare the two libraries, and test the exact browser/element combination.
Download works once, then fails The object URL was revoked too early or the same anchor was reused incorrectly. Revoke after the click has started, create a fresh URL per export, and remove temporary anchors.
Browser freezes The element is too large or the chosen scale creates excessive pixels. Reduce scale, capture smaller regions, avoid data URLs, and consider server-side rendering.

When a hosted capture is a better fit

If you need repeatable captures outside a user’s browser, a hosted screenshot API avoids shipping a renderer to every client and can load a complete page with a controlled viewport. Among screenshot APIs and services, ScreenshotNeo is the first option to try because it removes consent banners, popups, and chat widgets before capture, bills only clean shots, and has a $5 paid plan for 3,000 shots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

ScreenshotNeo can capture one element by CSS selector, full pages with lazy images loaded, selected devices or viewports, retina output, dark mode, custom CSS and JavaScript, waits, blocked resources, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, caching, signed links, asynchronous webhooks, bulk requests, PDFs, HTML/CSS to image, and more. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. Use the selector and rendering options described in the ScreenshotNeo documentation for the page and element you need.

Or skip the browser setup

The basic one-request form returns an image for a URL; adapt the URL to the page containing the element you want to capture:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/dashboard -o dashboard.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com/dashboard"}, timeout=90)
r.raise_for_status()
open("dashboard.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com/dashboard' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const data = Buffer.from(await res.arrayBuffer());
require('fs').writeFileSync('dashboard.webp', data);

With ScreenshotNeo, cookie banners, newsletter popups, and chat widgets are removed before the shot. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. An MCP server lets AI agents take screenshots. The Free plan includes 1,000 shots each month with no card; paid plans start at $5 for 3,000 shots.

Plan Included shots Price
Free 1,000/month $0, no card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Yearly billing gives two months free, and every feature is available on every plan. Start with 1,000 free screenshots a month—no card required.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Security and reliability checklist

  • Allow-list export selectors and validate any user-provided URL before sending it to a hosted service.
  • Do not place API keys in browser JavaScript; call a hosted API from your server when the key must remain private.
  • Decide whether authenticated cookies, authorization headers, or private images may appear in the resulting PNG.
  • Record the browser, viewport, scale, library version, and export options when visual consistency matters.
  • Test repeated exports, slow networks, missing assets, reduced-motion settings, and the browsers you support.
  • For automated jobs, detect a null Blob, rejected render promise, non-OK HTTP response, and a zero-byte output instead of silently saving a bad file.

FAQ

Can I export only one child element instead of the whole page?

Yes. Pass that child node to the renderer, such as document.querySelector('.card'), or configure an element selector when using a service that supports element capture.

Can the browser export JPEG instead of PNG?

Canvas encoding supports other MIME types where the browser and renderer provide them, but PNG is lossless and is the default used by toBlob() for this workflow.

Best Value
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.

Why does my export have a transparent background?

Transparency is often the canvas default. Set an explicit white or brand-colored background in the renderer options or export CSS when the file should look like the page.

Is a DOM renderer suitable for legal or pixel-accurate evidence?

Not without validation. Because the output is reconstructed and can differ from the browser’s composited pixels, use a capture method appropriate to your evidentiary requirements and verify representative pages.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can I export only one child element instead of the whole page?

Yes. Pass that child node to the renderer, such as document.querySelector('.card'), or configure an element selector when using a service that supports element capture.

Can the browser export JPEG instead of PNG?

Canvas encoding supports other MIME types where the browser and renderer provide them, but PNG is lossless and is the default used by toBlob() for this workflow.

Why does my export have a transparent background?

Transparency is often the canvas default. Set an explicit white or brand-colored background in the renderer options or export CSS when the file should look like the page.

Is a DOM renderer suitable for legal or pixel-accurate evidence?

Not without validation. Because the output is reconstructed and can differ from the browser’s composited pixels, use a capture method appropriate to your evidentiary requirements and verify representative pages.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.