To use html2canvas, install the package, import its default export in browser-side JavaScript, select an element, and await html2canvas(element, options). The result is a canvas you can display or export. It reconstructs an image from the DOM and supported styles; it is not a native browser screenshot, so the result may differ from what the browser displays.
Install html2canvas and initialize it
The official getting-started guide documents installation with npm and importing the package as an ES module. Use the package in code that runs in a browser, such as a page bundled with a frontend build tool. The project lists modern evergreen browsers, including Chrome and Chromium-based browsers, Firefox, and Safari; it is not suitable for Node.js. See the official getting-started guide and examples and browser information for current distribution details.
- Install the package in your project:
npm install html2canvas. - Import the default export in a browser-side JavaScript module.
- Select the DOM element you want to render, and check that it exists.
- Call
html2canvas(element, options)and await the returned Promise. - Use the resulting canvas to display the capture or export it as an image.
This complete example assumes the page contains an element with id="capture". It appends the rendered canvas to the document after the target element:
import html2canvas from 'html2canvas';
async function captureElement() {
const element = document.querySelector('#capture');
if (!element) {
throw new Error('Capture element not found');
}
const canvas = await html2canvas(element);
document.body.appendChild(canvas);
return canvas;
}
captureElement().catch((error) => {
console.error('Could not render the element:', error);
});
The call is asynchronous. Await it inside an async function, or use .then() if your code is not using async/await. The official guide describes both Promise chaining and async/await; it also lists package-manager and CDN installation alternatives. Check that page for the current instructions for the distribution method you choose rather than assuming a CDN address or release version.
Recommended Free Tools
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Display or download the canvas
The returned value is a regular <canvas> element, not a PNG file or data URL. Append it to the page to display it, or call a canvas export method. For example, this browser-side function exports a PNG using a temporary download link:
async function downloadCapture() {
const element = document.querySelector('#capture');
if (!element) {
throw new Error('Capture element not found');
}
const canvas = await html2canvas(element);
const link = document.createElement('a');
link.download = 'capture.png';
link.href = canvas.toDataURL('image/png');
link.click();
}
downloadCapture().catch((error) => {
console.error('Could not create the PNG:', error);
});
The filename in download is the suggested download name. If you need another supported canvas image format, pass its MIME type to toDataURL() and use a matching file extension. A large canvas can consume substantial browser memory, so test the output size on the devices and pages your application needs to support.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Adjust the capture with options
Pass a second object to html2canvas(element, options). The following options cover common adjustments documented in the html2canvas configuration reference and examples.
| Option | What it changes | When to use it |
|---|---|---|
scale |
Render scale; the documented default is window.devicePixelRatio. |
Set an explicit value when you need predictable output dimensions or a different sharpness-versus-size trade-off. |
backgroundColor |
The canvas background when the DOM does not specify one. Set it to null for a transparent background. |
Use a solid color for an opaque export, or null when transparency is wanted and supported by the output format. |
x, y, width, height |
The crop region used for rendering. | Capture a particular area rather than the whole selected element. Check the official configuration reference for the coordinate and dimension behavior relevant to your layout. |
useCORS |
Attempts to load images using CORS. | Try it when external images are missing and their servers permit cross-origin access. It does not bypass browser security rules. |
proxy |
Specifies a proxy URL for cross-origin resources. | Use a suitable proxy when direct cross-origin access is unavailable. The proxy must be able to retrieve the resource appropriately. |
ignoreElements |
A callback can exclude matching nodes from the render. | Omit dynamic controls or content that should not appear in the output. |
data-html2canvas-ignore |
Marks an element so it is ignored. | Use this attribute directly in markup when a particular node should always be excluded. |
windowWidth, windowHeight |
The viewport dimensions used during rendering, which can affect media queries and long-content captures. | Set them when the render should use dimensions other than the current browser window; they can also help with content cut off by canvas dimensions. |
onclone |
Lets you modify the cloned document used for rendering. | Make capture-specific changes without changing the live page the visitor is using. |
For example, this call requests a transparent canvas, chooses an explicit render scale, and excludes elements carrying the ignore attribute:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
const element = document.querySelector('#capture');
if (!element) throw new Error('Capture element not found');
const canvas = await html2canvas(element, {
backgroundColor: null,
scale: 2,
ignoreElements: (node) => node.hasAttribute?.('data-html2canvas-ignore')
});
Choose a scale with the final use in mind: increasing it can make details sharper, but also increases the canvas dimensions and the work required to render and export it. If the output should reflect a particular responsive layout, set the viewport options deliberately and verify the page’s media-query behavior.
Understand what html2canvas can and cannot render
html2canvas does not take a native screenshot of browser pixels. It traverses the DOM and rebuilds an image from the information it can read and the CSS it supports. A style, effect, or browser rendering detail may therefore look different or be missing. The project explains this distinction in its documentation about how html2canvas works. If your requirement is an exact capture of rendered browser pixels, verify the output against the real page rather than assuming visual equivalence.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Remote assets have an additional restriction: browsers enforce same-origin and CORS rules. Directly loading a cross-origin image for a readable canvas requires the resource’s server to allow the relevant CORS access. The useCORS option attempts CORS loading; it cannot grant permission the remote server has not provided. A configured proxy may be appropriate if it can retrieve the resource. Cross-origin iframes cannot be rendered because browser security restrictions prevent access to their documents. See the official FAQ for the project’s explanation of these restrictions.
Troubleshoot missing, inaccurate, or cut-off output
- The function throws or nothing is appended: Confirm that the selector matches an element at the time the function runs. If the target is created later by application code, call html2canvas after it is present.
- An image is missing: Check whether it is cross-origin and whether its server permits CORS. Try
useCORS: trueonly when the server supports it; otherwise, use an appropriate proxy or an image hosted where your page can access it. A setting in html2canvas cannot override the browser’s security policy. - Content inside an iframe is missing: If the iframe is cross-origin, html2canvas cannot read its document. Browser restrictions prevent rendering that content through this method.
- The output differs from the page: This can happen because html2canvas reconstructs an image from the DOM and supported CSS rather than copying browser pixels. Check which content or styling is unsupported, and simplify or adjust the capture-specific DOM when practical.
- The canvas is blank or cut off: Check the target’s dimensions and the browser’s canvas size limits. The official FAQ suggests setting
windowWidthorwindowHeightto match the element’s scroll dimensions when viewport sizing is the cause. Large canvases may still exceed browser limits. - The capture is blurry or too large: Review
scaleand the element’s dimensions. Higher scale increases output size and resource use; test an explicit scale against the quality and file size you actually need. - The wrong responsive layout appears: Check the viewport used for rendering and the page’s media queries. Set
windowWidthandwindowHeightif the capture should use different viewport dimensions.
For further configuration details, consult the official options reference and FAQ.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Or skip the browser setup
html2canvas is useful when you need to render a DOM element already available to your browser-side code. If you want a website screenshot from a URL instead, ScreenshotNeo provides a screenshot API and MCP server for developers. One GET request can return a screenshot or PDF; see the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- Before capture, it accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. Responses identify the page verdict and billing status in
X-Page-VerdictandX-Billedheaders. - Its MCP server offers
take_screenshot,get_page_info, andcapture_pdftools for AI agents, including Claude, Cursor, and other MCP clients. - The Free plan includes 1,000 screenshots a month without a card. Paid plans start at $5 for 3,000 screenshots; yearly billing gives two months free. Every feature is available on every plan.
Try ScreenshotNeo free: sign up for 1,000 screenshots a month with no card.
Frequently Asked Questions
Can html2canvas capture a website by URL alone?
No. Its basic call takes a DOM element available to browser-side code, not a URL to open and capture. For URL-based screenshots, use a browser automation workflow or a screenshot service such as ScreenshotNeo.
Quick Recap
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.

