Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
Canvas

How to Hide Elements From html2canvas Screenshots

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

The simplest way to keep an element out of an html2canvas image is to add data-html2canvas-ignore to that element. For conditional rules, use the ignoreElements option; for changes that should affect only the rendered copy, use onclone. These approaches remove or alter content for the canvas render without necessarily changing what visitors see.

Choose the right hiding method

Need Best method What changes
Always exclude one known element data-html2canvas-ignore The marked element is omitted from the render.
Exclude elements based on a class, attribute, or rule ignoreElements A predicate decides which elements are removed.
Change content or styles only while rendering onclone The cloned document is edited; the live page remains unchanged.
Hide an element on the page itself display: none or visibility: hidden The browser hides it, and html2canvas’s visibility tests show both as hidden.

Hide one fixed element with data-html2canvas-ignore

Add the attribute to any element that should never appear in captures:

<button class="share-button" data-html2canvas-ignore>Share</button>
<div class="cookie-banner" data-html2canvas-ignore>
  Accept cookies
</div>

Then capture the desired container in the normal way:

html2canvas(document.querySelector('#invoice'))
  .then(canvas => document.body.appendChild(canvas));

The attribute is intentionally simple: it requires no selector lookup and no callback. It is useful for print buttons, floating controls, consent notices, debug labels, and other interface chrome that should not be part of an exported image.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#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

Marking a parent also excludes its descendants

If you put the attribute on a wrapper, the wrapper and its children are excluded together. Place it on the smallest element that should disappear when you need the rest of the surrounding layout to remain.

Conditionally exclude elements with ignoreElements

Use ignoreElements when the decision depends on a class, data attribute, state, or another property. The option receives each element and should return true for elements to omit. Its documented default is a predicate that returns false.

const target = document.querySelector('#report');

html2canvas(target, {
  ignoreElements: (element) => {
    return element.matches(
      '.screen-only, [data-export="false"], button'
    );
  }
}).then(canvas => {
  document.querySelector('#preview').replaceChildren(canvas);
});

This example excludes buttons, elements with the screen-only class, and anything explicitly marked data-export="false". A predicate can also inspect an element’s ID, ARIA role, or other application state:

html2canvas(document.body, {
  ignoreElements: (element) => {
    return element.id === 'floating-help' ||
           element.getAttribute('aria-hidden') === 'true';
  }
});

Keep the predicate fast and side-effect free

html2canvas evaluates the predicate while traversing the document. Prefer cheap checks such as matches, classList.contains, or getAttribute. Do not mutate the live DOM inside the predicate; use onclone when rendering requires changes.

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
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

Change only the render clone with onclone

onclone is the right choice when the page must stay interactive and visually unchanged, but the screenshot needs temporary edits. html2canvas creates a cloned document, calls your callback, and renders that clone.

const target = document.querySelector('#dashboard');

html2canvas(target, {
  onclone: (clonedDocument) => {
    const clone = clonedDocument.querySelector('#dashboard');
    clone.querySelectorAll('.remove-in-export').forEach(node => {
      node.remove();
    });

    const notice = clone.querySelector('.live-status');
    if (notice) notice.textContent = 'Status captured for export';
  }
}).then(canvas => {
  const link = document.createElement('a');
  link.download = 'dashboard.png';
  link.href = canvas.toDataURL('image/png');
  link.click();
});

Because the callback receives the cloned document, removing a node there does not remove it from the page the user is viewing. This also lets you add export-only classes, replace animated content with a stable value, or adjust styles for a print-like composition.

Hide with a clone-only style

html2canvas(document.querySelector('#card'), {
  onclone: (doc) => {
    const style = doc.createElement('style');
    style.textContent = `
      .export-only-hidden { display: none !important; }
      .export-compact { margin: 0 !important; }
    `;
    doc.head.appendChild(style);
    doc.querySelector('.toolbar')?.classList.add('export-only-hidden');
    doc.querySelector('.card')?.classList.add('export-compact');
  }
});

Use this instead of briefly changing the live page when flicker, layout shifts, or event-handler interference would be a problem.

CSS hiding: display:none and visibility:hidden

The project’s visibility test demonstrates that elements using display: none and visibility: hidden are hidden from its render tests.

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.
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.
<div class="toolbar" style="display: none">Controls</div>
<div class="watermark" style="visibility: hidden">Draft</div>

These declarations also affect the actual page. display: none removes the element from layout, so nearby content can move. visibility: hidden keeps its layout space while making it invisible. If the user-facing page must not change, prefer the ignore attribute, ignoreElements, or onclone.

Complete examples

Export a card while omitting controls

async function exportCard() {
  const card = document.querySelector('#profile-card');
  const canvas = await html2canvas(card, {
    backgroundColor: '#ffffff',
    ignoreElements: (element) => {
      return element.matches('.card-actions, [data-no-capture]');
    },
    onclone: (doc) => {
      doc.querySelector('.animated-counter')?.classList.add('freeze');
    }
  });

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

document.querySelector('#export').addEventListener('click', exportCard);

Use the marker attribute for a reusable component

function addExportIgnoredClass(root) {
  root.querySelectorAll('.tooltip, .menu-trigger').forEach((node) => {
    node.setAttribute('data-html2canvas-ignore', '');
  });
}

const root = document.querySelector('#component');
addExportIgnoredClass(root);
html2canvas(root);

Why an excluded element may still seem visible

  • The wrong node was marked: inspect the rendered container and place the attribute on the actual element being traversed, not only on a separate overlay or portal root.
  • A parent or sibling draws the visual: a shadow, background, pseudo-element, or duplicated component can remain after the target node is removed.
  • Styles are not fully reproduced: html2canvas rebuilds an image from DOM information rather than taking a native browser screenshot. Its supported-features reference lists properties such as box-shadow, filter, and object-fit as unsupported; differences can therefore be unrelated to the ignore rule.
  • The clone callback targets the live document: query through the clonedDocument argument inside onclone, not through the global document.
  • The capture happens too early: wait until the target exists and its content has settled. If images or fonts are still loading, the output can differ even though the element was correctly excluded.

Canvas size, long pages, and blank output

html2canvas renders into an HTML canvas, whose dimensions are limited by the browser, operating system, and hardware. The project’s FAQ gives historical browser-specific limits; treat those figures as environment-dependent rather than universal current guarantees.

For a blank or cut-off result, capture a smaller element first, split a very long page into sections, and ensure the render viewport reflects the content dimensions:

const element = document.querySelector('#long-report');
const canvas = await html2canvas(element, {
  windowWidth: element.scrollWidth,
  windowHeight: element.scrollHeight
});

Large canvases consume substantial memory. Resize or paginate the output when the destination is a document, email, or thumbnail rather than a full-resolution archive.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Images, cross-origin content, and fidelity limits

html2canvas can only use information available to the page and does not capture browser pixels natively. Cross-origin images without appropriate permission can taint a canvas or fail to appear, and unsupported CSS can produce visual differences. Test the exact markup, image hosting policy, and installed html2canvas release used by your application.

Hiding an element does not solve an unrelated cross-origin image problem elsewhere in the capture. Isolate the target, remove unnecessary media with ignoreElements or onclone, and verify the result before offering it as a download.

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

Or skip the browser setup

If you need a clean screenshot of a URL rather than a canvas assembled inside your page, ScreenshotNeo returns PNG, JPEG, WebP, or PDF from one request. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result.

Use the API documentation at https://screenshotneo.com/docs/ for all options. A minimal cURL request is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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}`);

ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Options include full-page lazy-image loading, CSS-selector element capture, dark mode, device presets, custom viewports, retina scale, PDF page controls, custom CSS and JavaScript, clicks, selector or network-idle waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous webhooks, bulk capture for up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work.

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.

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is on every plan. Create your free ScreenshotNeo account to get started.

Troubleshooting checklist

  1. Confirm the capture target contains the element you intend to exclude.
  2. For a permanent omission, add data-html2canvas-ignore directly to that node.
  3. For rules, log the predicate’s matches and return true only for nodes that should be removed.
  4. For render-only edits, make every query through the document passed to onclone.
  5. Check whether a pseudo-element, parent background, or duplicate overlay creates the remaining pixels.
  6. Reduce the capture area if the canvas is blank, truncated, or extremely large.
  7. Review unsupported CSS and cross-origin images before changing the ignore logic.

Frequently Asked Questions

Can I hide an element only for one screenshot and show it immediately afterward?

Yes. Put the temporary removal or style change in onclone; html2canvas edits the cloned document used for rendering, so the live page is not changed.

Does data-html2canvas-ignore require a value?

No. The attribute can be present without a value, for example data-html2canvas-ignore=””.

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

Will ignoring a child remove its space from the layout?

The element is excluded from the rendered representation, but surrounding layout behavior depends on the remaining DOM and styles. If you need adjacent content to reflow, use a clone-only style such as display:none.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.