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

Extra white space at the bottom of an html2canvas image usually means the capture area is taller than the content you intended to keep—not that html2canvas has a universal “trim whitespace” bug. Measure the target element and the returned canvas first. Then choose the remedy that matches your intent: size the cloned viewport to the element for a complete scrollable capture, capture a smaller content node, or define an explicit crop with x, y, width, and height. Also test the page at the top and bottom because a version-specific issue report associated one blank offset with scroll position.

Start by measuring the pixels you actually captured

Do not begin by subtracting an arbitrary number of pixels. The “blank” area may be legitimate overflow, a wrapper’s reserved height, a responsive-layout change, or a browser canvas-limit failure. Log the selected node, its layout dimensions, and the canvas dimensions:

const element = document.querySelector('#capture');

const rect = element.getBoundingClientRect();
console.table({
  rectHeight: rect.height,
  clientHeight: element.clientHeight,
  scrollHeight: element.scrollHeight,
  rectWidth: rect.width,
  clientWidth: element.clientWidth,
  scrollWidth: element.scrollWidth,
  pageScrollX: window.scrollX,
  pageScrollY: window.scrollY
});

const canvas = await html2canvas(element);
console.table({
  canvasWidth: canvas.width,
  canvasHeight: canvas.height
});
  • getBoundingClientRect().height is the element’s visible border-box height at the current scale and scroll position.
  • clientHeight is the inner height, generally excluding borders and including the element’s visible padding.
  • scrollHeight includes content that overflows vertically and is the relevant target when you want the entire scrollable element.
  • The canvas dimensions show what html2canvas actually allocated, which can be larger than the visible box.

If you passed document.body, a page shell, or a wrapper with intentional empty space, the canvas may be accurately reproducing that larger node. The html2canvas examples demonstrate selecting a specific element; use the smallest node that contains the content you want.

Choose the fix based on the intended output

Capture the complete scrollable element

For a full capture of a scrollable component, set the cloned rendering viewport to the element’s scroll dimensions:

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
const element = document.querySelector('#capture');

const canvas = await html2canvas(element, {
  windowWidth: element.scrollWidth,
  windowHeight: element.scrollHeight
});

document.body.appendChild(canvas);

This is the approach recommended in the official html2canvas FAQ when a full-element capture is blank or cut off. windowWidth and windowHeight describe the cloned page’s viewport; they are not a whitespace-cropping switch. Because viewport dimensions can trigger different CSS media queries, inspect the result at the new width and height. A breakpoint may legitimately change wrapping, columns, or component height and therefore change the image.

Capture a smaller node instead of a tall wrapper

If the content occupies only part of a card or page shell, move the selector to the content node:

const content = document.querySelector('#capture-content');
const canvas = await html2canvas(content);
const png = canvas.toDataURL('image/png');

Removing an outer element with a fixed height, min-height, bottom padding, or reserved footer space is safer than trimming the finished bitmap. Check computed styles in DevTools for those properties and for absolutely positioned children that extend the wrapper’s scrollable area.

Rank #2
Sale
KOOTION USB C Flash Drive 32GB 2 in 1 OTG USB 3.0/Type C Thumb Drive Dual Drive USB C Memory Stick for Smartphone Laptop Tablet PC, Blue
  • 2 in 1: USB C + USB 3.0, 32GB usb c flash drive has dual ports, usb 3.0 port is applied to all devices which have usb 3.0 interface and usb c port is widely used in all Android smartphones with OTG function
  • High Speed USB 3.0: Read speed up to 90 MB/s, Write speed up to 30 MB/s, the speed of USB 3.0 interface is faster than USB 2.0, save time to wait, increases work productivity. Note: Speed will be limited if you use the USB key in the USB 2.0 interface
  • Large Compatibility: The USB 3.0 Connector is compatible with USB 3.0 & USB 2.0 backward USB 1.1 devices, such as Laptop, Desktop, Car Audio, Tablet, TV, Speakers, Projector. USB-C port is compatible with all Android Smartphones
  • Expand Storage: Good performance in storing, transferring and sharing digital data with families, friends, colleagues, customers. It can expand the capacity of smartphone, you can watch movies or share pictures when you go on vacation with your family
  • Note: Make sure your smartphone is equipped with OTG function and need to open OTG function in Settings when you plug memory stick, then you can transfer easily data bewteen different devices

Crop to a deliberately measured region

When the desired output is a subregion, use html2canvas’s crop options. The configuration reference documents x, y, width, and height; the values must describe the pixels you intend to retain:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const element = document.querySelector('#capture');
const rect = element.getBoundingClientRect();

const cropX = rect.left;
const cropY = rect.top;
const cropWidth = rect.width;
const cropHeight = /* measured content height, not an arbitrary subtraction */ rect.height;

const canvas = await html2canvas(element, {
  x: cropX,
  y: cropY,
  width: cropWidth,
  height: cropHeight
});

Use coordinates derived from the intended boundary. A crop that is too short hides the same pixels you were trying to preserve. Verify at the browser zoom and device-pixel ratio used in production; a CSS-pixel measurement and a bitmap-pixel measurement are not interchangeable when scaling is involved. See the official configuration reference for the complete option set.

Check scroll position before changing CSS

Re-run the exact capture at the top and at the bottom of the page:

Rank #3
Sale
Lexar D40E 64GB 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
window.scrollTo({ top: 0, left: 0 });
const topCanvas = await html2canvas(document.querySelector('#capture'), {
  scrollX: window.scrollX,
  scrollY: window.scrollY
});

window.scrollTo({ top: document.documentElement.scrollHeight, left: 0 });
const bottomCanvas = await html2canvas(document.querySelector('#capture'), {
  scrollX: window.scrollX,
  scrollY: window.scrollY
});

A 2019 issue report for html2canvas 1.0.0-rc.3 described a large blank offset when the reporter had scrolled to the bottom and said that returning to the top fixed that example. It is evidence of a diagnostic possibility, not proof that scrolling causes every bottom gap or that the report applies to current releases. If your result changes with scroll position, make scrollX and scrollY explicit and inspect fixed-position elements. These options matter when rendering content such as sticky headers or fixed overlays.

Distinguish extra layout from an oversized canvas

If the image is both unusually tall and partly blank or cut off, investigate browser canvas limits before cropping. The FAQ warns that maximum canvas dimensions vary by browser and platform. When a canvas exceeds a limit, “the browser silently produces a blank or partially rendered output without throwing an error,” which makes the failure difficult to diagnose. The guidance is not a stable cross-device threshold.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Capture a shorter section and compare the result.
  • Reduce the target’s width, height, or scale and see whether rendering becomes complete.
  • Split a very tall document into sections rather than allocating one enormous bitmap.
  • Record browser, operating system, viewport, device-pixel ratio, html2canvas version, and canvas dimensions when reporting the problem.

A true layout gap normally appears consistently at the element boundary. A canvas-limit failure often produces missing content as well as blank pixels.

Use onclone for a narrow, capture-only adjustment

The configuration reference includes onclone, which runs after html2canvas clones the document and before it renders. It lets you change the cloned element without modifying the live page:

Rank #4
2-Pack 128GB USB C Flash Drive Dual Type C + USB A Memory Stick Jump Drive 2-in-1 Thumb Drive for Storage and Backup (128GB*2 Black&Blue)
  • 2-in-1 Dual Design: Features both USB-C and USB-A connectors, making it compatible with phones, tablets, MacBooks, PCs, and laptops-no adapter needed
  • Wide Compatibility: Works seamlessly with USB A and USB C devices, ensuring reliable file transfers across smartphones, computers, and more
  • Ample Storage Options: Available in 16GB/32GB/64GB/128GB providing plenty of space for photos, videos, music, and documents
  • Portable & Lightweight: Compact and durable design for travel, school, or daily use-take your files anywhere
  • Plug-and-Play Convenience: No software or drivers required; simply insert into USB-C or USB-A ports and start transferring files instantly
const element = document.querySelector('#capture');

const canvas = await html2canvas(element, {
  onclone: (clonedDocument) => {
    const cloned = clonedDocument.querySelector('#capture');
    if (!cloned) return;

    // Example: remove a known capture-only spacer.
    cloned.querySelector('.capture-spacer')?.remove();
  }
});

Keep this override specific. Do not apply a global reset or broad height rule that makes the clone unlike the page users see. First identify the exact spacer, padding, fixed-height shell, or component responsible, then change only that node in the clone.

Common causes and targeted fixes

Symptom Likely explanation What to try
Canvas matches a tall page shell The selected node includes reserved height or a footer area. Capture the content child or remove the intentional spacer in onclone.
Content below the fold is missing The cloned viewport is shorter than the scrollable element. Set windowWidth and windowHeight to scrollWidth and scrollHeight.
Gap changes after resizing A media query changes the cloned layout. Use a deliberate viewport and inspect responsive breakpoints before cropping.
Gap appears only at page bottom Scroll state, fixed elements, or a version-specific rendering issue may be involved. Compare top and bottom captures and set scrollX/scrollY explicitly.
Bottom and other regions are blank or clipped The bitmap may approach a browser/platform canvas limit. Reduce size or split the capture; check the FAQ’s platform-specific warnings.
Irregular spacing inside text or a component Font, CSS, or a renderer-version difference rather than extra bottom height. Reproduce with a minimal node and check fonts and version.

A 2022 issue reports variable spacing with html2canvas 1.4.1 but does not establish a generally applicable fix. Treat issue reports as clues for a controlled reproduction, not as guarantees.

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

A repeatable troubleshooting workflow

  1. Confirm the selector. Log the node and make sure it is not body, an application shell, or a wrapper with intentional empty height.
  2. Record dimensions. Compare bounding-rectangle height, clientHeight, scrollHeight, and canvas height.
  3. Decide what “correct” means. Choose full scrollable content, the visible box, or a measured subregion.
  4. Set viewport dimensions for full output. Use the FAQ pattern, then check for media-query changes.
  5. Test scroll states. Capture at the top and bottom with explicit scroll options.
  6. Try a minimal target. Remove unrelated overlays, fonts, animations, and large siblings to isolate the renderer.
  7. Check size limits. If the canvas is very large or partly blank, reduce it or split it before changing layout.
  8. Apply onclone only after diagnosis. Remove or resize the exact cloned node that creates the unwanted height.
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 service that returns a screenshot rather than maintaining browser capture code, ScreenshotNeo provides a GET-based website screenshot API and an MCP server for AI agents. It accepts consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.

One call is enough:

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

See the ScreenshotNeo documentation for options such as full-page lazy-image loading, CSS-selector element capture, device presets or custom viewports, retina scale, PDF output, custom CSS and JavaScript, click-before-capture actions, selector or network-idle waits, request blocking, headers, cookies, user-agent and authorization, timezone and geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous jobs, webhooks, bulk capture, usage data, and the OpenAPI specification. Its parameter names also work with those used by other screenshot APIs, which can simplify migration.

Best Value
Samsung Type-C USB Flash Drive 256GB, USB 3.2 Gen 1, Up to 400MB/s
  • USB-C STORAGE ON THE GO: This sleek drive is supported by Samsung NAND flash and is incredibly compact to fit in the palm of your hand; Count on reliable performance and fast transfer speeds while staying compact
  • PERFORMANCE WITH SPEED: No need to choose between performance and reliability; Experience a fast, powerful flash drive that transfers 4GB files in just 11 seconds with up to 400MB/s USB 3.2 Gen 1 read speeds and is backward compatible with USB 3.0/2.0
  • MODERN MEETS ICONIC: The ultra-sleek USB-C drive looks as good as it performs; Featuring a reversible plug, the Type-C inserts into your devices seamlessly every time; Transfer large files with style and ease
  • ALWAYS CONNECTED: USB-C is compatible across devices, including laptops, tablets, phones and cameras, with enough space for 63,730 photos or maximum 12 hours of 4K video; With up to 256GB of storage space, this pocket-sized thumb drive comes in handy wherever you go
  • TOUGH & TRUSTED: Files stay secure, no matter the terrain; Samsung's flash memory technology makes the Type-C a trustworthy drive to store your valuable data; It's waterproof, shock-proof, magnet-proof, temperature-proof, and X-ray-proof body, plus it's backed by a 5-year limited warranty
import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

ScreenshotNeo includes take_screenshot, get_page_info, and capture_pdf MCP tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.

FAQ

Should I always set windowHeight to scrollHeight?

No. Do it when the intended image includes the complete scrollable element. For a viewport-sized screenshot, keep the viewport appropriate to that design and use a measured crop or a smaller target when necessary.

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

Can CSS overflow: hidden remove the white area?

Only if overflow is the reason the selected element is taller than the intended content, and it may hide real content. Measure first; do not use it as a blind fix.

Why does a screenshot service help with this particular problem?

It moves rendering to a managed capture endpoint, so you do not have to maintain html2canvas viewport, scroll, clone, and canvas-limit handling in your page. It does not repair an html2canvas canvas you already generated.

Frequently Asked Questions

Does changing the output image format remove bottom whitespace?

No. PNG, JPEG, and WebP encode the pixels that were captured; changing format does not change the capture rectangle or layout.

What should I include in a bug report?

Provide a minimal reproducible page, the exact html2canvas version, browser and operating system, viewport and device-pixel ratio, scroll position, capture options, target dimensions, and the resulting canvas dimensions.

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.

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.