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

For a quick image export inside a web app, a DOM-to-image library may be enough. If you need a screenshot that matches what a browser actually rendered, use browser automation or a screenshot service instead: libraries such as html2canvas reconstruct the page from DOM and styles rather than capturing the browser surface, so unsupported CSS, cross-origin assets, and canvas limits can change the result.

The right choice depends on where capture runs, how closely output must match the page, what assets are involved, and which output format you need. Test with your real content and target browsers before committing.

What HTML-to-image libraries do—and what they do not

HTML-to-image libraries turn a DOM node or page content into an image-like output. They are useful when you want an in-browser export button, a generated preview, or a downloadable image without launching a separate browser process.

They are not all screenshots in the strict sense. html2canvas traverses the DOM and reads style information to construct a canvas representation. Its documentation cautions that the result may not match the page’s real appearance because it “does not make an actual screenshot.” See the html2canvas documentation. This distinction matters when the page uses CSS features the library does not support, or when visual fidelity must match a browser-rendered page.

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

A headless browser, by contrast, renders the page and captures its output. The html2canvas FAQ points to Playwright or Puppeteer when server-side screenshots are required. That approach brings different operational needs: browser versions, fonts, viewport, network state, and timing all affect the capture.

Which approach fits your use case?

Approach Best fit Important limitation
html2canvas Client-side export from a page element when the required CSS and resources are supported. Reconstructs DOM and styles rather than taking a true screenshot; CSS coverage is finite and it is not suited to Node.js.
html-to-image Client-side DOM-node output when its documented formats and filtering options suit the application. Documented output helpers do not guarantee fidelity for every CSS feature, browser, or external asset.
Playwright or Puppeteer Server-side or CI capture when browser-rendered output is the requirement. You must operate a browser environment and manage rendering inputs such as fonts, viewport, waits, and network state.
Hosted screenshot API Teams that prefer a managed renderer rather than operating capture infrastructure. Compare data handling, options, reliability, and recurring cost for your workload; available documentation alone does not establish suitability.

The html-to-image README documents PNG, JPEG, SVG, Blob, canvas, and pixel-data helpers, as well as a filter option. Those are useful capabilities, but they do not establish that every output will reproduce your production page exactly.

Using html2canvas for a client-side export

The package is installed as @html2canvas/html2canvas. The basic workflow is to select an element, wait for its content to be ready, call the library, and export the returned canvas. Confirm the current package instructions in the official html2canvas repository before adding it to a project.

  1. Install the package: npm install @html2canvas/html2canvas
  2. Mark the content: give the element you want exported an id, such as report-card.
  3. Wait for resources: make sure dynamic content, images, and fonts are ready before capture.
  4. Capture and save: use the code below from a browser-side module or script.
import html2canvas from '@html2canvas/html2canvas';

async function downloadReport() {
  await document.fonts.ready;

  const element = document.getElementById('report-card');
  if (!element) {
    throw new Error('Could not find #report-card');
  }

  const canvas = await html2canvas(element, {
    useCORS: true,
    backgroundColor: '#ffffff'
  });

  const link = document.createElement('a');
  link.download = 'report.png';
  link.href = canvas.toDataURL('image/png');
  link.click();
}

const button = document.getElementById('download-report');
button?.addEventListener('click', () => {
  downloadReport().catch((error) => console.error('Image export failed:', error));
});

Here useCORS requests cross-origin image loading in a way that may work when the remote server permits it; it does not bypass browser security policy. The white background is explicit so the export is not left to an implicit or transparent background choice. Adjust it to the intended output and verify the downloaded file in your target browsers.

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.
Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

The library exposes options for rendering behavior, but support and effects can vary with the page and browser. Consult its configuration documentation for the option set rather than assuming a setting will make unsupported CSS or blocked content work.

Using html-to-image

html-to-image is another browser-side option when you want an image from a DOM node and its documented output helpers suit your export. A simple PNG download looks like this:

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

async function downloadCard() {
  await document.fonts.ready;

  const node = document.getElementById('report-card');
  if (!node) {
    throw new Error('Could not find #report-card');
  }

  const dataUrl = await toPng(node);
  const link = document.createElement('a');
  link.download = 'report.png';
  link.href = dataUrl;
  link.click();
}

document.getElementById('download-report')?.addEventListener('click', () => {
  downloadCard().catch((error) => console.error('Image export failed:', error));
});

For other needs, the project README documents helpers for JPEG, SVG, Blob, canvas, and pixel data, plus a filter option to exclude selected nodes. Choose a helper based on what your application consumes: a Blob can fit a file-upload flow, while a data URL is convenient for a direct download but may be less suitable for very large output.

When to use a real browser capture

Use browser automation when the requirement is “capture what the browser rendered,” when the capture must run on a server or in CI, or when a DOM reconstruction cannot handle the page’s styles and assets reliably. Playwright and Puppeteer are both named by the html2canvas FAQ as alternatives for server-side screenshots. This is a different strategy, not a guarantee of pixel-perfect output: page state, installed fonts, browser version, viewport, and wait conditions still matter.

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

For a repeatable capture, define and control the conditions that influence rendering:

  • Pin the browser/runtime version used for capture.
  • Set the viewport and device scale deliberately.
  • Ensure fonts and images have loaded before the capture.
  • Wait for a selector, application-ready signal, or appropriate network state instead of relying on an arbitrary short delay.
  • Use stable test data and account for animations, live content, and responsive breakpoints.

If you do not want to operate a browser, a hosted screenshot API is another category to evaluate. ScreenshotNeo is a website screenshot API and MCP server for developers. Its documentation describes a one-request capture workflow and output as PNG, JPEG, WebP, or PDF. Managed capture can reduce browser setup, but you should still test the output against your target pages and requirements.

Or skip the browser setup

For a server-side capture without running Playwright or Puppeteer yourself, call the ScreenshotNeo API with your API key and target URL. See the ScreenshotNeo API documentation for authentication and options.

curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://stripe.com 
  -o shot.webp

ScreenshotNeo can accept a cookie or consent banner like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets before the capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

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

The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account to try the API.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

How to compare libraries and screenshot strategies

Do not choose by a “pixel perfect” claim unless you can reproduce that result on the page and browsers you care about. A practical evaluation fixture should include your real fonts, images, CSS effects, responsive layout, and dynamic content.

  • Fidelity: Check filters, transforms, shadows, typography, and layout against the browser-rendered page.
  • Runtime: Decide whether capture must run in the visitor’s browser, a server, a CI worker, or a hosted service.
  • Assets and security: Identify same-origin and cross-origin images, fonts, iframes, and existing canvas content.
  • Output: Confirm whether you need PNG, JPEG, SVG, Blob, raw pixel data, PDF, or a saved browser screenshot.
  • Dimensions: Test the largest expected element and output size in each required browser.
  • Operations: For automation or hosted APIs, decide how to handle browser versions, fonts, waits, secrets, data handling, and recurring costs.

No single option is established as the winner for every use case. A DOM library can be the simplest solution for a contained client-side export; browser capture is the better starting point when server execution or browser-rendered fidelity is central. Hosted APIs trade some infrastructure work for an external service dependency.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

External images are missing or the canvas export fails

A cross-origin image can taint a canvas unless the remote resource permits CORS. The browser does not let a DOM-image library bypass that policy. Configure the asset host to return suitable CORS headers, use a permitted proxy, or keep the image same-origin. Cross-origin iframes are blocked from access through contentDocument; sandboxed iframes without allow-same-origin have a similar restriction. Existing canvases tainted by cross-origin content may also be unreadable.

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

Some CSS looks different

html2canvas documents that CSS properties need individual implementation and that some are not supported. Check its supported behavior for the property in question and test a small fixture. If the visual result must match the browser rather than an implemented subset, prototype with a headless browser.

The output is blank, clipped, or partly rendered

Canvas dimension limits vary by browser and platform. The html2canvas FAQ warns that an oversized canvas can become blank or partly rendered; its rough figures should not be treated as stable limits. Reduce the captured area or output scale, split a very large export into sections, and test the actual size on every supported browser.

Fonts or dynamic content are absent

Capture too early and the export may reflect fallback fonts, unloaded images, or an incomplete interface. Wait for application content to be ready and for document.fonts.ready before invoking a client-side capture. For browser automation, use explicit readiness conditions appropriate to the page.

The code fails in Node.js

html2canvas runs in a browser and depends on browser APIs; it is not suited to Node.js. Use a browser automation tool such as Playwright or Puppeteer for server-side screenshot work, or evaluate a hosted screenshot API.

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

FAQ

Can I capture a cross-origin iframe with an HTML-to-image library?

Not by reading its contents from a different origin: browser security blocks access to the iframe document. The iframe owner would need to provide an allowed integration or expose suitable content through another route.

Should I use PNG or JPEG?

Choose based on the destination and the output helper or capture service you use. PNG is a common choice for sharp text and transparency; JPEG is useful when a compressed photographic image is acceptable and transparency is not needed. Verify the actual output quality and size for your content.

Does html-to-image guarantee that every CSS feature will render correctly?

No. Its README lists output capabilities, not universal CSS or browser fidelity guarantees. Validate the styles and assets used in your own page.

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.

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