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

Use html2canvas’s x, y, width, and height options. Convert edge coordinates with x = left, y = top, width = right - left, and height = bottom - top. Validate the bounds before rendering so an inverted rectangle cannot produce an empty or confusing result.

Convert four edges into html2canvas options

html2canvas represents a crop as a rectangle whose origin is its top-left corner. The official configuration defines x as the crop canvas x-coordinate and y as the crop canvas y-coordinate; width and height define the output canvas dimensions. In other words, the right and bottom values are edges, not sizes.

Your bound html2canvas option Formula
Left edge x left
Top edge y top
Right edge width right - left
Bottom edge height bottom - top

This is the same rectangle model used by canvas APIs: coordinates locate the upper-left corner, while dimensions describe how far the rectangle extends. The html2canvas project’s documented instruction is to “Pass x, y, width and height options to crop the output.”

Complete JavaScript example

The following example captures the element with four inclusive-style edge coordinates. In practice, the right and bottom edges act as exclusive limits because the dimensions are calculated by subtraction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Acer Predator Helios Neo 18 AI Gaming Laptop | Intel Core Ultra 9 Processor 275HX | NVIDIA GeForce RTX 5070 Ti | 18" WQXGA 240Hz G-SYNC | 32GB DDR5 | 2TB Gen 4 SSD | Killer Wi-Fi 6E | PHN18-72-9474
  • Desktop-Level Performance, Anywhere: Get legendary gaming performance with the Intel Core Ultra 9 275HX processor, delivering ultra-smooth gameplay and future-ready AI (Up to 13 NPU TOPS). Offload tasks like background removal and audio optimization to the NPU for seamless streaming and gaming, while Intel Application Optimization enhances performance on classic titles.
  • Game-Changing Realism: Powered by NVIDIA Blackwell architecture, GeForce RTX 5070 Ti Laptop GPU unlocks the game changing realism of full ray tracing. Equipped with a massive level of 992 AI TOPS horsepower, the RTX 50 Series enables new experiences and next-level graphics fidelity. Experience cinematic quality visuals at unprecedented speed with fourth-gen RT Cores and breakthrough neural rendering technologies accelerated with fifth-gen Tensor Cores.
  • Supreme Speed. Superior Visuals. Powered by AI: DLSS is a revolutionary suite of neural rendering technologies that uses AI to boost FPS, reduce latency, and improve image quality. DLSS 4 brings a new Multi Frame Generation and enhanced Ray Reconstruction and Super Resolution, powered by GeForce RTX 50 Series GPUs and fifth-generation Tensor Cores.
  • The Ultimate in Ray Tracing and AI: NVIDIA RTX is the most advanced platform for full ray tracing and neural rendering technologies that are revolutionizing the ways we play and create. Over 700 games and applications use RTX to deliver realistic graphics and incredibly fast performance with cutting-edge AI features like DLSS Multi Frame Generation.
  • Immersive Depth and Detail: At 18 inches with a 16:10 aspect ratio, the pristine WQXGA screen offering vibrant colors with up to 100% DCI-P3 operates at a fast 240Hz refresh and 3ms overdrive response time. Alongside the suite of features from NVIDIA G-SYNC and NVIDIA Advanced Optimus, you're guaranteed that whatever's on-screen is a distinct viewing delight.
const element = document.querySelector('#invoice');

const bounds = {
  top: 100,
  left: 50,
  bottom: 500,
  right: 650,
};

if (!Number.isFinite(bounds.left) ||
    !Number.isFinite(bounds.top) ||
    !Number.isFinite(bounds.right) ||
    !Number.isFinite(bounds.bottom)) {
  throw new TypeError('All crop bounds must be finite numbers');
}

if (bounds.right <= bounds.left || bounds.bottom <= bounds.top) {
  throw new Error('right must exceed left and bottom must exceed top');
}

html2canvas(element, {
  x: bounds.left,
  y: bounds.top,
  width: bounds.right - bounds.left,
  height: bounds.bottom - bounds.top,
}).then((canvas) => {
  document.body.appendChild(canvas);

  // Export when you need a file or data URL:
  const pngUrl = canvas.toDataURL('image/png');
  console.log(pngUrl);
});

For the sample values, html2canvas starts at (50, 100), renders a 600-pixel-wide region, and renders a 400-pixel-high region. The source element must be large enough to contain that rectangle; otherwise the visible result may be clipped by the element or by the browser’s renderable area.

Choosing coordinates correctly

Element coordinates versus viewport coordinates

Choose coordinates in the coordinate space used by the element and html2canvas render. If your bounds come from getBoundingClientRect(), those values are viewport-relative and may need to be translated when the crop is intended to be relative to a particular element or document. A simple element-relative crop usually starts at left: 0 and top: 0; a crop beginning 40 CSS pixels inside the element uses x: 40.

Scrolling and off-screen content

A crop can refer to content outside the currently visible viewport, but the element must be laid out with the dimensions you expect. For long pages, set the rendering window to the element’s scroll dimensions when appropriate:

const width = element.scrollWidth;
const height = element.scrollHeight;

html2canvas(element, {
  windowWidth: width,
  windowHeight: height,
  x: 0,
  y: 0,
  width,
  height,
});

The html2canvas FAQ notes that matching windowWidth and windowHeight to the element’s scroll dimensions can help with very large pages. It does not remove browser canvas-size limits, so extremely large captures can still be truncated or empty.

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

CSS pixels, device pixels, and scale

Coordinates are normally supplied in CSS-pixel space. The scale option controls the backing resolution of the rendered canvas and defaults to window.devicePixelRatio. A crop that is 600 CSS pixels wide can therefore have a backing width of 1,200 pixels on a device with a 2× device-pixel ratio. Keep the crop geometry in CSS pixels, and adjust scale when you need predictable output dimensions or lower memory use.

html2canvas(element, {
  x: bounds.left,
  y: bounds.top,
  width: bounds.right - bounds.left,
  height: bounds.bottom - bounds.top,
  scale: 1, // predictable 1 CSS pixel to 1 backing pixel
});

Validation and reusable crop helper

Putting conversion and validation in one function prevents negative dimensions and makes it easier to reuse saved selections.

function captureBounds(element, bounds, options = {}) {
  const { top, left, bottom, right } = bounds;

  for (const [name, value] of Object.entries({ top, left, bottom, right })) {
    if (!Number.isFinite(value)) {
      throw new TypeError(`${name} must be a finite number`);
    }
  }
  if (right <= left) throw new RangeError('right must exceed left');
  if (bottom <= top) throw new RangeError('bottom must exceed top');

  return html2canvas(element, {
    ...options,
    x: left,
    y: top,
    width: right - left,
    height: bottom - top,
  });
}

captureBounds(
  document.querySelector('#chart'),
  { top: 24, left: 32, right: 832, bottom: 624 },
  { backgroundColor: '#fff' }
).then((canvas) => {
  document.querySelector('#preview').replaceChildren(canvas);
});

Keep the validation before calling html2canvas. A zero-width or zero-height rectangle is not a useful capture, and an inverted rectangle indicates a selection or coordinate-conversion bug.

Direct cropping versus post-cropping

Approach Advantages Costs and risks
Pass x, y, width, height to html2canvas Renders only the requested region, reducing the work and memory needed for a large unused area; the bounds are explicit. Coordinates must be in the correct render space, and large or cross-origin content can still fail during rendering.
Capture a larger canvas, then draw a sub-rectangle to a second canvas Useful when you need several crops from one already-rendered image or when selection coordinates are easier to apply after capture. The initial canvas can consume substantially more memory; scaling and device-pixel-ratio conversions must be handled when copying pixels.

For one region, direct cropping is usually the simpler path. Post-cropping is sensible when multiple output rectangles share one expensive render.

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 #3
msi Katana 15 HX 15.6” 165Hz QHD+ Gaming Laptop: Intel Core i9-14900HX, NVIDIA Geforce RTX 5070, 32GB DDR5, 1TB NVMe SSD, RGB Keyboard, Win 11 Home: Black B14WGK-016US
  • Intel Core i9 HX Power for Elite Gaming: Dominate demanding titles with the Intel Core i9-14900HX and its 24-core hybrid architecture, delivering fast load times, high FPS, and smooth multitasking.
  • GeForce RTX 5070 With Ray Tracing & DLSS 4: Powered by NVIDIA Blackwell, the RTX 5070 delivers stronger ray tracing, higher FPS, faster AI upscaling, and more responsive gameplay—ideal for competitive and cinematic gaming.
  • QHD 165Hz, 100% DCI-P3 for Ultra-Clear Combat: The QHD 165Hz display reveals more detail, reduces motion blur, and boosts visibility in fast-paced games while delivering richer, more accurate colors.
  • Cooler Boost 5 for Sustained Performance: Dual fans and a 5-heat-pipe share-pipe design keep the CPU and GPU cool, maintaining stable frame rates during long gaming marathons.
  • 4-Zone RGB Keyboard + Full Game-Ready Ports: Customize your setup with a 4-zone RGB keyboard and highlighted WASD keys. Includes USB-C Gen 2, HDMI up to 8K, multiple USB-A ports, RJ45, Wi-Fi 6E & Hi-Res Audio.

Cross-origin images and canvas security

Images loaded from another origin can be blocked or can taint the canvas. The html2canvas FAQ documents useCORS: true when the image server returns a suitable Access-Control-Allow-Origin header. If the remote server does not permit CORS, use a same-origin proxy or remove the image before capture.

html2canvas(element, {
  x: bounds.left,
  y: bounds.top,
  width: bounds.right - bounds.left,
  height: bounds.bottom - bounds.top,
  useCORS: true,
});

useCORS is not a permission bypass: the image response still needs an appropriate header, and credentials or restrictive policies may require a proxy designed for your application.

Large pages, memory, and reliability

  • Prefer the smallest useful rectangle instead of capturing an entire document and discarding most of it.
  • Lower scale when a high-density backing canvas is not required; backing dimensions and memory grow with the scale factor in both directions.
  • Split very tall reports into several captures when the browser’s canvas limits are exceeded.
  • Wait until fonts, images, and application data have rendered before calling html2canvas; otherwise the crop can be geometrically correct but visually incomplete.
  • Test at the viewport widths your users actually use. Responsive layout changes can move the content beneath fixed bounds.

When a capture is blank or truncated, first reduce the rectangle and scale, then check the element’s scroll dimensions and browser console for security errors. A successful promise only means html2canvas produced a canvas; it does not guarantee that every external resource was drawable.

Common problems and fixes

The crop is shifted

Cause: viewport coordinates were supplied as element coordinates, or scroll offsets were applied twice. Fix: decide whether the bounds are relative to the target element, document, or viewport, then convert once into the target element’s render space.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
15.6" Laptop with Win 11, N4020 CPU, 4GB RAM, 128GB, FHD 1080P Display
  • Vibrant 15.6" FHD IPS Display: Experience stunning visuals on a large 15.6-inch Full HD (1920x1080) IPS screen. With narrow bezels and wide viewing angles, this laptop offers an immersive experience for streaming movies, online classes, or working on documents with crystal-clear detail
  • Efficient Daily Performance: Powered by the Intel Celeron N4020 processor and 4GB LPDDR4 RAM, this notebook delivers reliable performance for web browsing, light multitasking, and school projects. The 128GB storage provides ample space for your essential files, photos, and apps
  • Modern Connectivity & PD Fast Charge: Equipped with a versatile Type-C PD 45W port for fast charging and high-speed data transfer. Combined with Dual-Band AC WiFi and Bluetooth, you’ll enjoy a stable and fast internet connection for seamless video calls and cloud-based work
  • Silent & Ultra-Portable Design: Featuring an advanced fanless cooling system, this laptop operates in total silence—perfect for libraries or late-night study sessions. Its sleek, lightweight body fits easily into backpacks, making it the ideal companion for students and commuters
  • Ready for Work & Play: Pre-installed with Windows 11 Home, offering a secure and user-friendly interface. Includes a HD webcam and high-quality speakers for clear communication. A practical choice for online learning, remote work, or everyday entertainment

The output is empty

Cause: the rectangle is outside the rendered content, dimensions are zero or negative, or a browser canvas limit was reached. Fix: log the four bounds and derived dimensions, confirm right > left and bottom > top, then try a smaller region and scale: 1.

Images disappear or export throws a security error

Cause: a cross-origin image lacks permissive CORS headers. Fix: enable useCORS only when the image host supports it, configure that host’s CORS policy, or proxy the image through your own origin.

The crop contains the old layout

Cause: capture ran before a framework update, web font, lazy image, or animation completed. Fix: wait for the relevant selector or resource in your application, disable or freeze animations for the capture, and call html2canvas after the final layout has been painted.

Only the visible portion is captured

Cause: the element or rendering window is smaller than its scrollable content. Fix: measure scrollWidth and scrollHeight, and pass suitable windowWidth and windowHeight values for a full-page render.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
AKCHART 15.6'' AI Laptop with Office 365 12GB RAM 256GB SSD Win 11 Laptops
  • Stunning 15.6" FHD IPS Display: Experience crisp 1920x1080 resolution on this 15.6 inch laptop with an IPS panel that delivers wide viewing angles and vivid colors. The narrow-bezel design maximizes screen real estate for comfortable viewing on this Win 11 laptop, whether you're studying or working.
  • Celeron J4105 Processor & 256GB SSD: Powered by a reliable Celeron J4105 processor paired with 12GB DDR4 memory and a fast 256GB M.2 SSD. This laptop computer supports SSD expansion up to 2TB and TF card expansion up to 1TB, so your storage grows with your needs. Delivers smooth multitasking for daily productivity.
  • AI-Powered Win 11 Laptop: Built-in AI features enhance your productivity with smart assistance for writing, summarizing, and task management. Pre-installed with Win 11 and includes Office 365 subscription. This student laptop is backed by 1-year warranty and 24/7 customer support.
  • All-Day 7000mAh Battery & 180° Hinge: The high-capacity 7000mAh battery keeps this laptop powered through long classes or meetings. The 180-degree lay-flat hinge lets you share your screen effortlessly during presentations. This durable laptop computer adapts to your dynamic workflow.
  • Versatile Connectivity Hub: Equipped with USB 3.2, Type-C, Mini HDMI, and 3.5mm audio jack to connect all your peripherals. Stay online anywhere with high-speed 5G WiFi and Bluetooth 4.2. This college laptop keeps you connected at home, in the library, or on the go.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For server-side or automated screenshots, ScreenshotNeo accepts a URL and returns PNG, JPEG, WebP, or PDF. Its crop-oriented options include full-page capture, CSS-selector element capture, viewport and device presets, custom CSS and JavaScript, waits, hidden selectors, and image resizing. A single request looks like this; see the ScreenshotNeo documentation for the current parameter reference.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Before capture, ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

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

When to use each method

  • Use html2canvas when the capture must happen inside the user’s browser and you already have the DOM element and local state.
  • Use direct bounds when you know the rectangle in the element’s coordinate space and want to avoid rendering unused pixels.
  • Use post-cropping when one render will produce several related rectangles.
  • Use a URL screenshot service when you need repeatable server-side jobs, PDFs, webhooks, bulk URLs, or an AI-agent workflow rather than browser code.

Frequently Asked Questions

Do right and bottom mean width and height in html2canvas?

No. They are edge coordinates in your own bounds object. Derive dimensions with width = right - left and height = bottom - top.

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.

Can I use fractional crop values?

Use finite numeric CSS-coordinate values. If your workflow requires exact pixel boundaries, normalize or round them consistently before rendering and keep the chosen scale documented.

Why does changing scale change the exported file dimensions?

The scale option changes the canvas backing resolution. Its default is window.devicePixelRatio, so one CSS-pixel crop can occupy multiple backing pixels on high-density displays.

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.