DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk2 min

The CSS Property That Fixes Dark Mode’s Ugly White Boxes

CSS color-scheme helps browser-controlled UI match dark mode, while author-styled white boxes need their own dark-mode CSS.

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.

The CSS property is color-scheme. It tells the browser which color schemes your page supports, so browser-controlled surfaces—such as form controls and scrollbars—can match dark mode. It does not recolor every white box on the page: backgrounds and other surfaces you style yourself still need dark-mode CSS.

What color-scheme fixes

Set color-scheme to tell the browser which schemes an element can be rendered in. The browser may then adapt its own interface colors, including form controls, scrollbars, and other browser-provided UI. This is useful when native controls stay glaringly light against a dark page.

As an Amazon Associate I earn from qualifying purchases.

The distinction matters: browser-controlled UI is not the same as page content. A panel with an explicit background-color: white is author-styled, so the browser does not automatically turn it dark just because the page declares color-scheme. The W3C describes the boundary this way: “While the prefers-color-scheme media feature allows an author to adapt the page’s colors to the user’s preferred color scheme, many parts of the page are not under the author’s control (such as form controls, scrollbars, etc).” W3C CSS Color Adjustment Module Level 1

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

Use color-scheme with your own dark-mode styles

For a page that supports both light and dark appearance, declare both schemes on the document root, then use prefers-color-scheme to style your own page colors according to the user’s preference:

:root {
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  body {
    color: #f2f2f2;
    background-color: #171717;
  }
}

The sample colors are illustrative; choose colors that suit your design. The light dark value signals support for both schemes—it is not a priority order. Add dark-mode rules for any author-styled surfaces that need to change, such as cards, borders, and text. MDN: color-scheme MDN: prefers-color-scheme

Tell the browser about the scheme early

You can also put a color-scheme declaration in the document head, before your stylesheets. This gives the browser the information early and can help avoid an unwanted flash while the page loads:

<head>
  <meta name="color-scheme" content="light dark">
  <link rel="stylesheet" href="styles.css">
</head>

The metadata complements your CSS; it does not replace the rules that set dark colors for your own page content. See MDN’s color-scheme meta reference.

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

Scope themes carefully

A root declaration is appropriate when the whole document supports both schemes. If only a component or region is designed for a particular scheme, color-scheme can instead be scoped to that element. MDN documents values including only light, light dark, and only dark; use a single-scheme declaration only when the region is genuinely usable in that scheme.

MDN documents only dark as invalid for the meta element because forcing a document into a scheme it cannot support may make it unreadable. Its reference says major browsers default to light if no other scheme is configured. MDN: <meta name="color-scheme">

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

Embedded content and theme toggles

prefers-color-scheme can also be used by embedded SVG and iframe content, including documented cross-origin cases when the embedding conditions are met. A host page cannot necessarily recolor an arbitrary third-party embed; the embedded content may control its own appearance. MDN: prefers-color-scheme

The examples above follow the user’s system preference. If your site has its own theme toggle, treat that selection as application state and ensure it takes precedence in your own styles; color-scheme and prefers-color-scheme alone do not implement the toggle’s behavior.

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.