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

A transparent PNG needs two things: a format that carries an alpha channel and a capture setting that removes the browser’s default page background. In Playwright or Puppeteer, save a PNG with omitBackground: true. In html2canvas, use backgroundColor: null. Then inspect every ancestor, pseudo-element, image, and iframe that could paint an opaque background. JPEG cannot preserve transparency, and a filename ending in .png does not prove that alpha data exists.

Choose the fix for your capture method

Method Transparency setting What it actually captures Main caveat
Playwright type: 'png' and omitBackground: true Pixels rendered by a real browser Opaque CSS on the page or target still appears
Puppeteer type: 'png' and omitBackground: true Pixels rendered by a real browser Opaque CSS on the page or target still appears
html2canvas backgroundColor: null A DOM/CSS reconstruction in a client-side canvas Unsupported CSS, cross-origin images, and cross-origin iframes can differ or disappear

If you need the closest representation of what Chromium actually displayed, use Playwright or Puppeteer. html2canvas is useful when the output must be produced in the browser, but its documentation explains that it rebuilds the image from DOM and CSS rather than taking an actual screenshot.

Playwright: capture a genuinely transparent PNG

Minimal runnable example

import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
await page.goto('https://example.com', { waitUntil: 'networkidle' });
await page.screenshot({
  path: 'capture.png',
  type: 'png',
  omitBackground: true
});
await browser.close();

omitBackground hides the default white page background and permits transparent pixels. Keep type: 'png'; JPEG has no alpha channel. PNG is Playwright’s documented default, but stating it explicitly prevents a later refactor from silently changing the output format.

Capturing one element

const card = page.locator('.logo-card');
await card.screenshot({
  path: 'logo-card.png',
  type: 'png',
  omitBackground: true
});

An element screenshot can still include an opaque color inherited from html, body, a wrapper, or the element itself. Transparency removes the browser’s synthetic background; it does not override your CSS.

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

Full-page, retina, and timing options

await page.screenshot({
  path: 'page.png',
  type: 'png',
  omitBackground: true,
  fullPage: true,
  scale: 'device'
});

fullPage changes the captured geometry and scale changes pixel density. Neither changes alpha behavior, so leave omitBackground: true enabled. Wait for fonts and images before the shot when layout stability matters:

await page.goto(url, { waitUntil: 'networkidle' });
await page.evaluate(() => document.fonts.ready);
await page.waitForLoadState('networkidle');
await page.screenshot({ path: 'ready.png', type: 'png', omitBackground: true });

Puppeteer: use the same alpha controls

Minimal runnable example

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 1440, height: 900, deviceScaleFactor: 1 });
await page.goto('https://example.com', { waitUntil: 'networkidle0' });
await page.screenshot({
  path: 'capture.png',
  type: 'png',
  omitBackground: true
});
await browser.close();

Puppeteer documents omitBackground as hiding the default white background and allowing transparency. The option only affects the default page background; a real CSS background remains visible.

Element and full-page captures

await page.locator('.badge').screenshot({
  path: 'badge.png',
  type: 'png',
  omitBackground: true
});

await page.screenshot({
  path: 'long-page.png',
  type: 'png',
  omitBackground: true,
  fullPage: true
});

html2canvas: set a null background

Basic browser-side capture

import html2canvas from 'html2canvas';

const node = document.querySelector('#artboard');
const canvas = await html2canvas(node, {
  backgroundColor: null
});
const png = canvas.toDataURL('image/png');
const link = document.createElement('a');
link.href = png;
link.download = 'artboard.png';
link.click();

html2canvas uses #ffffff as its documented default background. Setting backgroundColor: null makes the canvas background transparent. Export as PNG; a JPEG data URL will flatten the result.

Apply capture-only CSS with onclone

const canvas = await html2canvas(document.querySelector('#artboard'), {
  backgroundColor: null,
  onclone: (clonedDocument) => {
    const cloned = clonedDocument.querySelector('#artboard');
    cloned.classList.add('capture-mode');
  }
});

onclone lets you alter the cloned document without changing the live page. It is useful for hiding controls or removing a decorative background only during export.

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

Know what html2canvas cannot promise

Because html2canvas reconstructs pixels from DOM and CSS, unsupported properties can produce differences from the browser. External images must satisfy the relevant CORS rules or be handled through a configured proxy. Cross-origin iframes cannot be rendered by the project, so redesign, proxy, or capture those regions separately. Filters, complex blend modes, masks, and other unsupported CSS effects may be missing or altered.

Find the opaque layer that is defeating transparency

A transparent target is not enough if something behind it is painted. Inspect the complete chain:

  1. Document root: check html and body backgrounds, including gradients and background images.
  2. Layout wrappers: inspect every ancestor between the target and the root for a color, image, pseudo-element, or positioned overlay.
  3. Target styles: remove unintended background and background-color declarations.
  4. Pseudo-elements: inspect ::before and ::after; they frequently draw full-size panels.
  5. Fixed UI: cookie banners, chat launchers, and newsletter modals may sit above the target even when visually subtle.
const backgrounds = await page.evaluate(() => {
  const nodes = [];
  for (let el = document.querySelector('#artboard'); el; el = el.parentElement) {
    const s = getComputedStyle(el);
    nodes.push({
      tag: el.tagName,
      id: el.id,
      className: el.className,
      backgroundColor: s.backgroundColor,
      backgroundImage: s.backgroundImage,
      opacity: s.opacity
    });
  }
  return nodes;
});
console.table(backgrounds);

Temporarily add an outline or a loud diagnostic color to each ancestor in DevTools. If the “transparent” area changes, you have found a painted layer rather than an encoding problem.

Verify alpha instead of trusting the filename

  1. Open the PNG over a white background.
  2. Open the same file over a dark background.
  3. Look at an area that should be empty. A real alpha channel reveals the test background through it.
  4. If both views show identical white pixels, inspect the capture option, CSS chain, and export format.

Some image viewers display transparency as a white checkerboard or white canvas. Use an editor or browser that lets you change the viewing background when diagnosing the file.

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

Common failures and precise fixes

Symptom Likely cause Fix
Entire image is white Default background was not omitted, or html2canvas used its default Use PNG with omitBackground: true, or backgroundColor: null
Only the outside margin is white An ancestor or pseudo-element has an opaque background Walk the background chain from target to html
Transparency works in browser automation but not html2canvas DOM reconstruction lacks support for a CSS effect or external asset Prefer a real browser screenshot, or simplify CSS and resolve CORS
Images are missing Cross-origin image rules blocked them Configure appropriate CORS/proxy handling or serve assets from an allowed origin
Iframe content is blank The iframe is cross-origin Capture it separately or redesign the composition
Edges look wrong or content is clipped Capture occurred before fonts/images loaded, or viewport/scale changed geometry Wait for fonts and network idle; set the intended viewport and scale
File extension says PNG but no alpha exists The bytes were converted to JPEG or flattened by another step Inspect the actual MIME type and export with a PNG encoder

Performance, reliability, and deployment choices

When Playwright or Puppeteer is the better fit

  • Pixel fidelity to browser rendering is important.
  • The page uses modern CSS, web fonts, scripts, or lazy-loaded images.
  • You need full-page screenshots, controlled viewports, or repeatable automation.
  • You can run a browser process on a server, worker, or CI machine.

Reuse a browser process for batches, create isolated pages or contexts per job, and wait on a meaningful selector when network idle is not reliable. Set timeouts, record the URL and viewport with each artifact, and treat authentication, robots rules, bot checks, and rate limits as part of the capture design.

When html2canvas is the better fit

  • The capture must happen inside the user’s browser.
  • You need a canvas for immediate client-side editing or upload.
  • The target uses CSS and assets that you have tested against html2canvas’s supported set.

Keep the target small when possible, avoid unnecessary redraws, and test external assets on the same origins and browsers your users actually use.

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

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or PDF, and its transparent-background option handles the browser work for you. Cookie and consent banners, newsletter popups, and chat widgets are removed before the shot. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. AI agents can call its MCP tools—take_screenshot, get_page_info, and capture_pdf.

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}`);

For transparent output and the full set of capture controls, see the ScreenshotNeo documentation. Every plan includes all features: full-page and selector capture, dark mode, device and viewport controls, retina scale, custom CSS and JavaScript, click and wait actions, request blocking, headers, cookies, user agent, authorization, timezone, geolocation, resizing, chosen-TTL caching, signed image links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. The parameter names used by other screenshot APIs also work for easier migration.

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

The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; higher plans are Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000. Yearly billing gives two months free. Create a free ScreenshotNeo account to start without a card.

FAQ

Can SVG or WebP be transparent?

Yes, those formats can carry transparency, but the settings in this guide specifically ensure PNG output retains an alpha channel. Confirm the actual encoded format after any conversion step.

Does transparent capture make a CSS background disappear?

No. It removes the browser’s default background. CSS colors, gradients, images, and overlays remain unless you change them.

Why does a checkerboard appear in my editor?

A checkerboard usually indicates that the editor is visualizing transparent pixels. Switch the editor’s canvas color to confirm that the underlying pixels are alpha, not white.

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

Frequently Asked Questions

Can I make only one area transparent while keeping a page background?

Yes. Capture the target element and make that element and any required ancestors transparent; leave unrelated page regions styled normally. For a full-page capture, every painted layer remains part of the result.

Will increasing scale improve transparency?

No. Scale changes pixel density and file size. It does not create or remove alpha data; keep the transparency option enabled independently.

What should I do if a consent banner changes the layout before capture?

Wait for the page to settle and dismiss or remove the banner before capturing. A service such as ScreenshotNeo can accept consent banners and remove known overlays before the shot.

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.

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.