🎨 The Dark Mode Query That Wasn’t the Only One Running
A prefers-color-scheme media query reads the operating system’s reported color scheme preference and switches a site’s own styles accordingly, which works correctly and predictably as long as the only thing deciding how the page looks is the page’s own stylesheet. A browser extension that forces a dark appearance onto every site by rewriting computed colors after the page renders operates at a completely different layer, applied after your stylesheet has already done its job, and the two systems can disagree without either one reporting an error – the media query correctly detects a light-mode system preference and renders light-mode styles, while the extension still forces a dark overlay on top of them a moment later, producing a combination of colors neither the page nor the extension ever actually intended together.
🔎 The Problem
@media (prefers-color-scheme: dark) {
body { background: #121212; color: #eaeaea; }
.card { background: #1e1e1e; border-color: #333; }
}
@media (prefers-color-scheme: light) {
body { background: #ffffff; color: #1a1a1a; }
.card { background: #f5f5f5; border-color: #ddd; }
}
/* This correctly renders the light-mode rules when the OS reports
a light preference - the media query itself is not wrong. A
browser extension with forced dark mode enabled then rewrites
the computed background and text colors AFTER layout, on top
of the already-correct light styles, producing a page where a
light-styled .card sits on a forced-dark body, with image and
icon contrast tuned for one scheme sitting on a background from
the other - a combination this stylesheet never had to account
for, because it assumes only one system is deciding the colors. */
✅ Fix: Don’t Assume Your Media Query Is the Only Thing Deciding Colors
- Reproduce the issue by actually enabling a forced-dark-mode browser extension during testing, rather than relying solely on the operating system’s own light/dark toggle, since that toggle alone never exercises the extension layer at all.
- Set an explicit color-scheme meta value or CSS property declaring which schemes the page actually supports, which gives some forced-dark extensions a stronger signal to respect the page’s own styling instead of overriding it uniformly.
- Avoid relying on an image, icon, or illustration whose contrast was tuned for only one color scheme, and prefer styling approaches – a background shorthand instead of separate layered properties, for instance – that degrade more predictably if something outside the page’s own stylesheet later adjusts individual color values.
⚠️ Why This Is Easy to Miss
- The media query itself is implemented correctly and passes every test that checks the operating system’s own preference toggle, so there is nothing in the stylesheet’s logic to suggest the final rendered result depends on anything beyond that one setting.
- A forced-dark-mode extension is specific to whichever browser and configuration an individual visitor happens to be running, so the mismatched colors only appear for a subset of visitors and never show up in a design review done on a clean, extension-free browser.
A color-scheme media query answers one question correctly – what did the operating system report – and has no say at all over what happens to the colors after that answer leaves its hands.




