What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Set html2canvas’s backgroundColor option to '#ffffff' when you render the element. The option paints an opaque white canvas behind the captured DOM:
html2canvas(element, { backgroundColor: '#ffffff' }).then((canvas) => {
document.body.appendChild(canvas);
});
If the live element or one of its descendants has transparent styling that must become white only in the screenshot, combine that option with onclone. The callback edits html2canvas’s cloned document, so your visible page remains unchanged.
Use backgroundColor: '#ffffff' for a white export
html2canvas renders the selected DOM into a canvas. Its backgroundColor setting controls the canvas fill when no background is supplied by the DOM. The documented default is #ffffff, but relying on that condition can be confusing when your page contains explicit transparent or other background declarations. Pass the value explicitly whenever a white result is required.
const element = document.querySelector('#capture');
html2canvas(element, {
backgroundColor: '#ffffff'
}).then((canvas) => {
document.body.appendChild(canvas);
});
The promise resolves with the rendered HTMLCanvasElement. You can append it for inspection, draw it elsewhere, or export it with the browser’s normal canvas APIs.
#1 Best Overall
A complete capture-and-download example
This example assumes html2canvas is already loaded and that the page contains an element with an id of capture.
const element = document.getElementById('capture');
if (!element) {
throw new Error('Capture element #capture was not found');
}
html2canvas(element, {
backgroundColor: '#ffffff'
}).then((canvas) => {
const link = document.createElement('a');
link.download = 'capture-white.png';
link.href = canvas.toDataURL('image/png');
link.click();
}).catch((error) => {
console.error('html2canvas capture failed:', error);
});
Keep the white value as a string. Both '#ffffff' and the equivalent CSS white notation 'white' express an opaque color, while null has a different meaning.
When the element’s CSS is transparent
backgroundColor sets the canvas-wide fill. It does not rewrite the styles of the element being rendered. If a transparent element, panel, or descendant needs a white CSS background during capture, use onclone:
const element = document.querySelector('#capture');
html2canvas(element, {
backgroundColor: '#ffffff',
onclone: (clonedDocument) => {
const clonedElement = clonedDocument.querySelector('#capture');
if (clonedElement) {
clonedElement.style.backgroundColor = '#fff';
}
}
}).then((canvas) => {
document.body.appendChild(canvas);
});
html2canvas calls onclone while it prepares the document clone used for rendering. The assignment changes only that clone; the original page keeps its transparent styling. This is useful when the page’s normal design must remain transparent but the exported image needs a white panel.
Targeting a descendant instead of the root
You can select a child inside the cloned document when only one region needs a fill:
html2canvas(document.querySelector('#capture'), {
backgroundColor: '#ffffff',
onclone: (clonedDocument) => {
const card = clonedDocument.querySelector('#capture .card');
if (card) {
card.style.backgroundColor = '#ffffff';
}
}
}).then((canvas) => {
document.body.appendChild(canvas);
});
Use a selector that is unique inside the capture. Check for a missing match, as shown, so a changed template does not cause a runtime exception.
White canvas versus white page CSS
These are separate layers:
- Canvas background:
backgroundColor: '#ffffff'fills the rendered canvas. - Capture-time DOM styling:
onclonechanges CSS in the cloned document before rendering. - Live-page styling: your ordinary stylesheet and inline styles continue to control the visible page.
A white page background in CSS does not guarantee the same export if the captured element itself remains transparent or if another element supplies the visible background. Conversely, the explicit canvas option can provide a white base without changing your production CSS. For predictable output, set the option explicitly and add an onclone rule only where a particular element’s own background must change.
How to keep a transparent result
Use backgroundColor: null when transparency is the desired output:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →html2canvas(document.querySelector('#capture'), {
backgroundColor: null
}).then((canvas) => {
document.body.appendChild(canvas);
});
The html2canvas documentation and changelog describe null as the intentional transparent-canvas setting. Do not use it for a white export: a transparent PNG can appear white or checkerboard depending on the viewer, but its pixels are not opaque white.
Choosing the option
| Goal | Configuration | Effect |
|---|---|---|
| Opaque white screenshot | backgroundColor: '#ffffff' |
Paints a white canvas background. |
| White only during capture | backgroundColor: '#ffffff' plus onclone |
Provides a white canvas and temporary CSS changes without editing the live DOM. |
| Transparent screenshot | backgroundColor: null |
Preserves transparency in the canvas. |
Exporting the rendered canvas
Once the promise returns, the canvas is an ordinary browser canvas. Append it while debugging, or convert it to an image in your application:
Rank #3
html2canvas(document.querySelector('#capture'), {
backgroundColor: '#ffffff'
}).then((canvas) => {
// Preview the result.
document.body.appendChild(canvas);
// Create a PNG data URL for an image element or download link.
const pngDataUrl = canvas.toDataURL('image/png');
console.log(pngDataUrl);
});
If you need a different file format, pass the MIME type supported by the browser to the canvas export method. The background decision is made during rendering; changing the export format does not turn a transparent render into an opaque one, so set backgroundColor before the promise resolves.
Troubleshooting transparent or unexpected output
The result is still transparent
- Confirm the option is on the same html2canvas call that produces the canvas you export.
- Check that the value is exactly an opaque color such as
'#ffffff', notnull. - Inspect any
onclonecode for a selector that fails to match the element you intended to style. - Make sure you are exporting the resolved
canvas, not a different canvas created elsewhere.
The page is white but the exported element is not
A body-level CSS background and the captured element’s background are different. Add the explicit canvas option. If the element or a child has its own transparent background that must become white, set that style in onclone.
Recommended Free Tools
The live page changed after capture
Move temporary style changes into onclone instead of modifying the real element before calling html2canvas. The callback receives the cloned document intended for rendering, leaving the source document untouched.
The callback throws a null-reference error
The selector probably did not match in the clone. Store the result of querySelector, test it, and then assign the style, as in the examples. Also verify that the selector is scoped to the captured markup and remains stable when your template changes.
The canvas appears white in one viewer and transparent in another
Check the actual configuration. null creates transparency even if a viewer displays transparent pixels against a white workspace. An explicit '#ffffff' produces opaque white pixels.
Rank #4
- Are you familiar with html5? Then get this "HTML5 HTML Logo Web Programmer Nerd Funny" featuring HTML logo. Perfect for computer programmer, developer, software developer and technician who does computer programming language, coding and gaming on internet.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
Performance and reliability considerations
Keep the capture call focused on the element you need. A smaller subtree generally means less DOM and styling work for the renderer. Apply only the onclone changes required for the export; broad selector rewrites can make the cloned render harder to reason about.
Use the returned promise for both success and failure handling. Rendering is asynchronous, so code that tries to export a canvas immediately after starting html2canvas can run before the pixels exist. A .catch() branch gives your UI a place to report a failed capture instead of silently producing no file.
For repeatable output, keep the background choice in one shared capture function rather than relying on each caller to remember it. A small wrapper also makes it easy to switch between white and transparent modes:
function renderCapture(element, transparent = false) {
return html2canvas(element, {
backgroundColor: transparent ? null : '#ffffff'
});
}
renderCapture(document.querySelector('#capture'))
.then((canvas) => {
document.body.appendChild(canvas);
});
This wrapper does not alter the DOM. If a particular component needs a temporary white CSS background, add an onclone callback for that call rather than changing the global stylesheet.
Or skip the browser setup
If you need a URL screenshot rather than a canvas rendered inside your own page, ScreenshotNeo provides a website screenshot API and MCP server. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status.
One request returns PNG, JPEG, WebP or PDF. The API supports full-page captures with lazy images loaded, CSS-selector element captures, custom CSS and JavaScript, dark mode, device and viewport settings, retina scale, waits, request blocking, cookies, headers, user agents, geolocation, caching and more. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.
Best Value
- Used Book in Good Condition
See the ScreenshotNeo API documentation for the complete option list. A minimal cURL call is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
There is a free allowance of 1,000 screenshots per month with no card required. Paid plans start at $5 for 3,000 screenshots; every feature is included on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account to try it.
Equivalent calls from Python and Node.js
For scripts or build pipelines, the same endpoint works without browser automation.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsPython
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)
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}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const data = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', data));
Use html2canvas when the pixels must come from an already-loaded in-page component and you need capture-only CSS control. Use the API approach when the input is a URL, you want server-side capture, or you want consent and failed-page handling outside the browser.
Frequently Asked Questions
Can I make only one component white while leaving the rest of the page transparent?
Yes. Capture the component and set its cloned element’s background in an onclone callback; do not change the live page stylesheet.
What happens if I omit backgroundColor?
html2canvas documents #ffffff as the default when the DOM does not specify a background, but an explicit value is clearer when you require a guaranteed white export.
Is null another spelling for white?
No. html2canvas uses null deliberately to request a transparent canvas.
Quick Recap
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.

