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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Attach a submit event listener, stop the browser’s normal navigation with event.preventDefault(), and pass the element you want to capture to html2canvas. It returns a Promise that resolves to a canvas; export that canvas as an image or display it on the page. If the image must reliably show the submitted values, render a receipt or preview from the submitted data and capture that element rather than assuming every browser will render live form controls identically.

What happens when a form is submitted?

A normal form submission may navigate away from the current page or reload it. If you want to capture the page before that happens, handle the form’s submit event and call preventDefault(). Then read the submitted values, update the content you intend to capture, and wait for html2canvas to finish before exporting the result.

There are two distinct targets you can capture:

  • The live form: Capture the existing form element. This is the smallest implementation, but verify that the current values of each control appear correctly in the browsers you support.
  • A receipt or preview: Build a separate element from the submitted data, display values as ordinary text, and capture that element. This takes more markup, but gives you more control over labels, formatting, and the content represented in the image.

The second approach is the safer choice when the image functions as a confirmation or record. It is a practical recommendation, not a guarantee that html2canvas always mishandles form controls.

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

Install html2canvas and prepare the page

Install the package using the package manager for your project. For example, in a project using npm:

#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
npm install html2canvas

The examples below assume a JavaScript module environment, with an element to submit and a separate element in which to render a receipt:

<form id="my-form">
  <label>
    Name
    <input name="name" required>
  </label>
  <label>
    Email
    <input name="email" type="email" required>
  </label>
  <button type="submit">Create receipt</button>
</form>

<section id="form-preview" aria-live="polite"></section>
<p id="capture-status" role="status"></p>

Keep the preview element in the document and give it the visual styles you want in the exported image. If it should not be visible to the user, do not hide it with a technique that removes it from rendering; instead, place it in an appropriate visible state during capture or use a dedicated preview area.

Capture submitted values as a receipt

This complete example prevents navigation, reads the submitted form with FormData, renders the values into a receipt, and downloads a PNG. It uses text nodes rather than inserting user input as HTML.

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.
import html2canvas from 'html2canvas';

const form = document.querySelector('#my-form');
const preview = document.querySelector('#form-preview');
const status = document.querySelector('#capture-status');

if (!(form instanceof HTMLFormElement)) {
  throw new Error('Could not find the form');
}
if (!(preview instanceof HTMLElement)) {
  throw new Error('Could not find the preview element');
}

form.addEventListener('submit', async (event) => {
  event.preventDefault();
  status.textContent = 'Preparing your receipt…';

  try {
    const data = new FormData(form);
    const name = String(data.get('name') ?? '');
    const email = String(data.get('email') ?? '');

    preview.replaceChildren();
    const heading = document.createElement('h2');
    heading.textContent = 'Form submission';
    preview.append(heading);

    for (const [label, value] of [['Name', name], ['Email', email]]) {
      const row = document.createElement('p');
      const strong = document.createElement('strong');
      strong.textContent = `${label}: `;
      row.append(strong, document.createTextNode(value));
      preview.append(row);
    }

    const canvas = await html2canvas(preview);
    const link = document.createElement('a');
    link.download = 'form-receipt.png';
    link.href = canvas.toDataURL('image/png');
    link.click();
    status.textContent = 'Receipt downloaded.';
  } catch (error) {
    console.error('Could not capture the form:', error);
    status.textContent = 'Could not create the image. Please try again.';
  }
});

Replace the example fields with the controls in your form. FormData can contain multiple values for a name, such as a group of checkboxes; use getAll() when you need every value rather than just one. A select, radio group, or checkbox should be represented in the receipt according to your application’s rules, rather than relying on the screenshot library to infer what the submission means.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

For applications that already have a reliable receipt component, update that component from the validated submission result, then pass it to html2canvas. Keep the event handler asynchronous and report failures to the user: capture and image export take time, and either may fail.

Capture the existing form instead

If a visual snapshot of the current form is sufficient, the handler can be shorter. This follows the documented pattern of passing a DOM element to html2canvas, then exporting the returned canvas:

import html2canvas from 'html2canvas';

const form = document.querySelector('#my-form');
const preview = document.querySelector('#form-preview');

form.addEventListener('submit', async (event) => {
  event.preventDefault();

  try {
    const canvas = await html2canvas(preview);
    const link = document.createElement('a');
    link.download = 'form.png';
    link.href = canvas.toDataURL('image/png');
    link.click();
  } catch (error) {
    console.error('Could not capture the form:', error);
  }
});

To capture the form itself, select the form as the target instead of preview. Before relying on that output, check that current text inputs, textareas, selects, checkboxes, and radio groups appear as intended in the browser and device combinations you support. One report against html2canvas 1.4.1 described a stale input value in Firefox 124.0.2 and iOS 17 Safari; that is an individual report, not proof of a universal failure or a statement about every version and control.

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

Export, display, or send the image

Download a PNG

The examples export PNG with canvas.toDataURL('image/png') and trigger a download through an anchor’s download attribute. Use a filename that describes the output, and do not assume that a successful capture means the user has received or saved a durable record. If the record matters, store the submitted data through your application’s normal server-side workflow as well.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Show the canvas in the page

Instead of creating a download link, append the canvas to a result container or replace a preview image with the rendered output. Provide an accessible textual confirmation too; an image alone does not make the form result available to users who cannot see it.

Use another format or crop

The target element can be a smaller child of the page when you want only a portion of the interface. The project examples also document cropping, scaling, and excluding marked elements. Consult the project’s documentation for the supported options in the version you install, and test the exact combination you use.

What html2canvas does—and what it does not do

html2canvas does not take a native screenshot of the browser window. It traverses the DOM and reconstructs an image on a canvas using information available to it. The project documentation cautions that “The screenshot is based on the DOM and as such may not be 100% accurate to the real representation but builds the screenshot based on the information available on the page.” That distinction explains why CSS support, form-control rendering, and browser behavior can affect the result.

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

It also means the image is not a substitute for browser-level evidence of exactly what appeared on screen. Treat the output as a rendered representation for the use case you tested, not as a guaranteed pixel-identical capture across browsers.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Options and limits to check

Cross-origin images

If the element contains images hosted on another origin, the image host must allow access through suitable CORS headers, or your application must use an appropriate proxy. The useCORS option can request CORS-enabled loading, but it cannot override browser security policy or make a server send the required headers. If an image taints the canvas, exporting it may fail. Prefer same-origin assets where practical, or configure a carefully controlled proxy.

CSS coverage and layout

CSS coverage is selective, so complex or unsupported styling may not match the browser’s visible rendering. Compare the generated image with the page and simplify or adapt the capture-specific styles when needed. A dedicated receipt often helps because it can avoid irrelevant application layout and styling.

Large or long elements

Canvas size limits vary by browser and device. For certain clipped-element cases, the project FAQ recommends setting windowWidth and windowHeight to the element’s scroll dimensions. Those dimensions are not a universal maximum or a guarantee that every large capture will work. Test on target devices and consider splitting very long content into smaller captures if a single canvas is unreliable.

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

Browser-only execution

html2canvas depends on browser objects such as window and document, so it is not suitable for running directly in Node.js as a server-side screenshot library. Run it in a browser context after the page and capture target exist.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting form captures

The image shows an old input value

  • Confirm that the value has reached the element you are passing to html2canvas before capture begins.
  • For a receipt, read the submitted data and render the values as text in a dedicated preview.
  • Test each control type and supported browser; the reported stale-value issue concerns one scenario and does not establish behavior for all controls.

Images are missing or PNG export fails

  • Check whether the image is cross-origin and whether its server returns suitable CORS headers.
  • Try useCORS: true only when the resource server supports CORS; otherwise use same-origin assets or a controlled proxy.
  • Remember that browser content restrictions still apply even when the option is enabled.

Fonts, effects, or styles look different

  • Identify which CSS feature differs in the rendered output.
  • Simplify that styling in the capture view or use a dedicated preview with more predictable markup.
  • Validate in each browser and device combination that matters to your application.

The result is clipped, blank, or too large

  • Check the target element’s dimensions and whether content is outside its rendered bounds.
  • For applicable clipped-element cases, try setting windowWidth and windowHeight to the element’s scroll dimensions.
  • Test the change on the devices you support; canvas limits differ and a dimension that works in one browser may fail in another.
  • Capture a smaller element or divide long content into sections if one large canvas remains unreliable.

The capture does not run on the server

Move the operation to client-side code after the DOM exists. In server-rendered applications, avoid evaluating code that needs window or document during server rendering.

Performance, reliability, and cost considerations

Capture is asynchronous, so keep the interface responsive and give the user a clear pending and failure state. The amount of DOM and the size of the resulting canvas affect the work involved; the project material does not establish a universal speed or memory figure. Avoid capturing a larger area than necessary, and test the largest realistic form or receipt on the least capable devices you support.

For important submissions, store the actual form data through your application’s normal persistence flow and treat the image as a convenience or presentation artifact. That way a browser-specific rendering problem does not become the only copy of the submission.

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

Or skip the browser setup

If the submitted content is available at a URL the API can reach, ScreenshotNeo can return an image or PDF from one GET request. This is a different workflow from capturing unsaved state in the current browser: make the receipt page available at a URL, and account for any access controls or private data before sending it to an external screenshot service.

cURL:

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

Python:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://stripe.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Replace the example URL with the page you want to capture. Check the ScreenshotNeo API documentation for request parameters and response handling. ScreenshotNeo removes cookie banners, popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed; and its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Learn more at ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Can html2canvas capture a form submission without navigating away?

Yes. Handle the form’s submit event and call event.preventDefault() before starting the asynchronous capture.

Can html2canvas run in Node.js?

No. It relies on browser objects such as window and document; run it in a browser context.

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.