logo of Screenshot for Web
Free toolsPlaygroundDocsBlogPricing
LoginDashboard

Company

HomeFeaturesPricingBlogFacts

Screenshot Tools

Website ScreenshotsFull Page ScreenshotsScrolling ScreenshotsWebsite HistoryPDF Generation APIScreenshot API

Legal

Terms of UsePrivacy PolicyCookie PolicyCopyrightSecurity

Support

FAQSupportContact UsAPI Status
screen shot for web logo

No clutter. No distractions. Just clean, full-page screenshots with smart customization.

© 2026 HYDRANODE LTD. All rights reserved.

Screenshot for Web is operated by HYDRANODE LTD, a company registered in England and Wales, company number 15672526. Registered office: 124 City Road, London, London, England, EC1V 2NX.

FacebookInstagramLinkedInYouTube
  1. Home
  2. Blog
  3. Guides

Dark-mode screenshots: prefers-color-scheme, forced dark and sites with no dark theme, tested

How to capture a page in dark mode with Puppeteer and Playwright, what we measured on nine sites, and what to do when a site has no dark theme.

Screenshot for Web·October 30, 2026·6 min read

Sources

  1. prefers-color-scheme, MDN
  2. Page.emulateMediaFeatures, Puppeteer docs
  3. Emulation guide, Playwright docs
  4. browser.newContext colorScheme option, Playwright docs
  5. Auto Dark Theme, Chrome for Developers
  6. Chrome DevTools Protocol, Emulation domain
  7. CSS Color Adjustment Module Level 1, W3C

How this article was made

Researched and drafted with AI assistance from the sources listed. The code was run and the captures and measurements were made on 30 October 2026 with Puppeteer 25.16.0 (Chrome 156.0.8078.47) and Playwright 1.64.1 (Chromium 156.0.8078.4), on a Mac set to light mode. Our free screenshot tool wasn't used, because it didn't respond when tried that day.

Capture any page without ads, banners or chat widgets, free and without an account.

Try the free tools

More articles

  • News

    Puppeteer 25.19 stops print and dark mode emulation from cancelling each other

    Before Puppeteer 25.19.0, emulateMediaType and emulateMediaFeatures reset each other, losing print or dark mode. Our tests, the fix and a workaround.

    November 26, 2026
  • News

    Chrome 158 drops XSLT: what it does to screenshots of sitemaps and feeds

    We captured eight live sitemaps in Chrome 156 and Chromium 158. Styled pages turn into raw XML, a red warning bar is already in captures, and two fixes work.

    November 9, 2026
  • Research

    Chrome DevTools' full-size screenshot: where it fails on long and lazy pages

    We ran DevTools' full-size screenshot on six long pages: it stops at 16,384 pixels and misses content that appears on scroll. Here's why, and the fixes that worked.

    November 8, 2026

To capture a page in dark mode, set prefers-color-scheme to dark before you load the page. That works only if the site has a dark theme: of the nine sites we tested, four changed and five kept the same full-page brightness as in light mode. For those five, the only way to get a dark capture is to have Chrome repaint the page, and the result is the browser's approximation, not the site's design.

This guide gives the code for both methods, the measurements from all nine sites, and the four ways a capture ends up in the wrong theme.

Setting the preference

prefers-color-scheme is the CSS media feature that reports whether a user asked for a light or dark theme, normally through an operating system or browser setting. A headless browser can report either value without touching the system setting.

In Puppeteer, use page.emulateMediaFeatures before goto:

const puppeteer = require('puppeteer');

async function capture(browser, url, scheme, path) {
  const context = await browser.createBrowserContext();
  const page = await context.newPage();
  await page.setViewport({ width: 1280, height: 800 });
  // Set the preference before goto, so scripts that read it once see it.
  await page.emulateMediaFeatures([{ name: 'prefers-color-scheme', value: scheme }]);
  await page.goto(url, { waitUntil: 'load', timeout: 30000 });
  await new Promise((resolve) => setTimeout(resolve, 1500));
  await page.screenshot({ path });
  await context.close();
}

(async () => {
  const url = process.argv[2];
  const browser = await puppeteer.launch();
  await capture(browser, url, 'light', 'light.png');
  await capture(browser, url, 'dark', 'dark.png');
  await browser.close();
  console.log('saved light.png and dark.png for', url);
})();

Run against react.dev, it printed saved light.png and dark.png for https://react.dev/. Comparing the two files with ImageMagick, about 1,023,700 of the 1,024,000 pixels differed.

In Playwright, set colorScheme on the context:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext({
    colorScheme: 'dark',
    viewport: { width: 1280, height: 800 },
  });
  const page = await context.newPage();
  await page.goto(process.argv[2], { waitUntil: 'load' });
  await page.waitForTimeout(1500);
  await page.screenshot({ path: 'dark-pw.png' });
  console.log(await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches));
  await browser.close();
})();

It printed true. Playwright's docs say colorScheme defaults to 'light', and that null hands the choice back to the system setting. Our test Mac was in light mode, so we couldn't observe what either library does by default on a machine set to dark. Set the value explicitly in both and the question doesn't arise.

What nine sites did

We captured each site three ways at 1280 × 800: light, dark preference, and forced dark (explained below). The brightness columns give the mean grey level of the full-page capture, where 0 is black and 1 is white. "Pixels changed" compares only the first screen of the light and dark-preference captures, counting pixels that differ by more than 3%. We removed the "HeadlessChrome" token from the user agent. A tenth site, Stack Overflow, answered 403 to all three captures, so we left it out.

SiteLightDark preferenceForced darkPixels changed, first screenDark theme?
react.dev0.950.230.16100%Yes
tailwindcss.com0.850.090.1197.2%Yes
example.com0.920.150.1599.8%Yes
developer.mozilla.org0.710.180.165.1%Yes
apple.com0.530.530.195.7%No
github.com (signed out)0.970.970.210%No
news.ycombinator.com0.930.930.160%No
gov.uk0.920.920.140%No
bbc.com/news0.690.690.150%No

Two rows show why a first-screen check can mislead. MDN's homepage opens with a dark hero in both themes, so only 5.1% of that screen changed, yet the full page dropped from 0.71 to 0.18. Apple's first screen also changed by a similar 5.7%, but its full-page brightness stayed at 0.53: there the change was an animated hero caught at a different moment, not a theme. Compare full pages, or a part of the page below the hero.

GitHub's signed-out homepage is a useful warning too. It declares <meta name="color-scheme" content="light dark">, and matchMedia returned true for dark, but the page stayed white because its root element was set to a light theme. A page saying it supports dark doesn't mean you'll get dark.

Three captures of the GitHub homepage. The light and dark-preference captures are identical and white; the forced-dark capture has a near-black background with light text and the green button unchanged.

Forced dark, for sites with no dark theme

Chrome can darken a page itself. The DevTools Protocol, the interface automation tools use to control Chrome, has a method for it, Emulation.setAutoDarkModeOverride, described as rendering all web contents using a dark theme. It's marked experimental, so it may change between versions.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setViewport({ width: 1280, height: 800 });
  const cdp = await page.createCDPSession();
  await cdp.send('Emulation.setAutoDarkModeOverride', { enabled: true });
  await page.goto(process.argv[2], { waitUntil: 'load', timeout: 30000 });
  await new Promise((resolve) => setTimeout(resolve, 1500));
  await page.screenshot({ path: 'forced.png' });
  // Chrome's documented test: a light-scheme element's canvas colour stops being white.
  const canvas = await page.evaluate(() => {
    const probe = document.createElement('div');
    probe.style.cssText = 'color-scheme: light; background-color: canvas; display: none';
    document.body.append(probe);
    return getComputedStyle(probe).backgroundColor;
  });
  console.log('canvas probe', canvas);
  console.log('prefers dark', await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches));
  await browser.close();
})();

On Hacker News it printed:

canvas probe rgb(18, 18, 18)
prefers dark false

Three things came out of testing it:

  1. It doesn't set the preference. prefers-color-scheme: dark stays false, so a site's own dark styles don't run. On react.dev, forced dark gave a different and darker page (0.16) than the site's real dark theme (0.23), as the image at the top of this article shows.
  2. It keeps photos and strong colours. In our captures the BBC's photos and red banner, Hacker News's orange bar and GitHub's green button all survived.
  3. only light didn't stop it. Chrome's Auto Dark Theme article says <meta name="color-scheme" content="only light"> or color-scheme: only light opts a page out, and the CSS specification says only forbids the browser from overriding the scheme. That article describes an Android origin trial from Chrome 96. In our test, on Chrome 156, a local page with the meta tag and another with the CSS rule both came out with an rgb(18, 18, 18) background. Launching with --enable-features=WebContentsForceDark gave the same result on the meta-tag page. BBC News, which carries the only light meta tag, was darkened as well. Don't count on the opt-out in a capture pipeline.

Use forced dark when you need a dark image and accept that nobody designed it. Label it as such if the capture will be used as evidence of how a site looks, because no real visitor with a dark preference sees that page.

Four ways to get the wrong theme

We built a local test page for each case and read a background pixel from the screenshot. White is 255,255,255 and the dark theme is 17,17,17.

CaseResult
CSS media query, preference set after goto17,17,17: works
Script that reads matchMedia once, preference set after goto255,255,255: stays light
The same script, preference set before goto17,17,17: works
Script that listens for changes, preference set after goto17,17,17: works
0.6 s CSS transition, preference set after goto, captured at once246,246,246: nearly white
The same transition, 800 ms later17,17,17: works
The same transition, preference set before goto17,17,17: works
Stored theme=light, preference dark255,255,255: stays light
Stored theme=dark, preference light17,17,17: stays dark

Setting the preference too late. Plenty of sites read the preference once, in a script, and add a class. If you change it after load, that script has already run. Playwright behaved the same way: page.emulateMedia({ colorScheme: 'dark' }) after goto left the page white until page.reload().

Catching a transition. Sites that animate between themes can be photographed mid-change if you switch after load. Setting the preference first avoids it, because there's nothing to animate.

A saved choice. A theme stored in localStorage commonly beats the preference. That's also a tool: on react.dev, with the preference set to dark, this script produced a light page, because the site reads a stored theme value:

const puppeteer = require('puppeteer');
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setViewport({ width: 1280, height: 800 });
  await page.emulateMediaFeatures([{ name: 'prefers-color-scheme', value: 'dark' }]);
  await page.goto('https://react.dev/', { waitUntil: 'load' });
  console.log('no stored', await page.evaluate(() => document.documentElement.className));
  await page.evaluateOnNewDocument(() => localStorage.setItem('theme', 'light'));
  await page.goto('https://react.dev/', { waitUntil: 'load' });
  console.log('stored light', await page.evaluate(() => document.documentElement.className));
  await browser.close();
})();
no stored dark platform-mac
stored light platform-mac

The key name is specific to each site, so inspect its storage first. This also matters when you reuse a saved browser session: if the account or profile has a stored theme, it may override what you set.

Assuming the page has dark at all. Five of our nine sites didn't. If you capture many sites, compare a light and a dark capture of each and treat "no difference" as a normal result, not a failure.

Embedded content

Images and frames follow along. MDN notes that an SVG used through <img> and an <iframe> can respond to prefers-color-scheme, based on the color-scheme of the parent element. On our test page, with the preference emulated as dark, an embedded SVG whose circle has a dark-mode fill turned black and an iframe switched to its dark background. So one setting covers the embedded parts we tried, as long as those documents define a dark style.

Which method to use

  1. Set prefers-color-scheme to dark before goto. This is the right answer whenever the site has a dark theme.
  2. Compare the full page against a light capture, to find out whether it does.
  3. If the site stores a theme, set that value before the page loads as well.
  4. If there's no dark theme and you still need a dark image, use forced dark and say that it's a browser rendering.
  5. Wait for the page to be ready as you would for any capture. Our guide to waiting before a screenshot covers that, and screenshots behind a login covers saved sessions.