Operating systems and browsers now let people choose a light or dark appearance, and websites can read that preference. Ignore it, and visitors who browse in dark mode in the evening are suddenly confronted with a glaring white page. But dark mode is technically and visually more demanding than most people think: simply flipping the colours is not enough.
Why Simple Inversion Doesn't Work
The most common mistake is applying filter: invert(1) to the entire page. The result is inverted photos, distorted brand colours and shadows that suddenly glow. Photos are the most delicate part: in his guide on web.dev, Thomas Steiner points to research showing that people do not like inverted photos. For simple icons, on the other hand, inversion usually works well.
Then there is perception. Mathematically, contrast is symmetrical: the WCAG contrast ratio is calculated from the relative luminance of the lighter and the darker colour, regardless of which one is the text and which the background. Black on white and white on black therefore produce exactly the same value. Yet they are perceived differently. The Nielsen Norman Group summarises the research as showing that people with normal vision perform better with dark text on a light background most of the time. A dark mode therefore needs its own, deliberately chosen colour values rather than a mechanical reversal of the light theme.
The Right Approach
Work with design tokens: Define colours not as fixed values but as CSS custom properties (variables) that take different values depending on the mode, such as --color-bg, --color-text, --color-surface and --color-accent. Components reference only the variable. A two-tier structure works well: base tokens hold the palette, while semantic tokens describe the role of a colour, for example "card background" or "muted text". Only the semantic layer switches between light and dark. This keeps dark mode maintainable as new components are added. If you already have a design system with defined brand colours, add the dark variants there rather than scattering them across the code.
A dark background doesn't mean black: Google's Material Components deliberately use dark grey rather than black for backgrounds and surfaces in the dark theme. The documentation gives two reasons: shadows remain more visible, and light text on dark grey reduces eye strain. The same principle applies to text. On web.dev, Thomas Steiner avoids pure white, because it appears to glow and bleed against the dark surroundings, and uses a slightly dimmed white instead.
Check accent colours: Brand colours that work well on white often look too harsh on dark grey or lack sufficient contrast. Define dedicated variants for dark mode and test them against the WCAG minimums: 4.5:1 for normal text and 3:1 for large text, meaning at least 18 point, or 14 point bold. These thresholds apply equally in both modes.
Adapt images and graphics: Logos with transparent backgrounds and dark lettering disappear on dark backgrounds. Provide alternative versions. With the <picture> element and a <source> using media="(prefers-color-scheme: dark)", the browser loads the right file automatically. Inline SVG icons should use currentColor so that they adopt the text colour. Photos can be toned down slightly with a CSS filter: in the survey described on web.dev, most respondents preferred slightly less vibrant images in dark mode.
Rethink shadows: Shadows that create depth on white are barely visible on a dark background. Material Design solves this by making surfaces lighter the higher they sit above the background. Applied to the web, this means cards, dropdowns and dialogues get a slightly lighter surface colour than the page background. The higher the layer, the lighter the surface.
Technical Implementation
The foundation is the prefers-color-scheme media query. It indicates whether someone has chosen a light or dark appearance in their operating system or browser. Add color-scheme: light dark to :root. This tells the browser that your page supports both modes, so it can render form fields and scrollbars to match, for example. Without it, these elements may stay light even though the rest of the page is dark.
Since May 2024, the CSS function light-dark() has also worked in the current versions of all major browsers. It takes two colours and returns the first or the second depending on the active colour scheme, without a separate media query. It also requires color-scheme: light dark. For a manageable set of tokens, this saves a lot of code. If your audience uses older browsers, you will need a fallback.
Also offer a manual toggle. Many people keep their operating system in dark mode but want to read a particular website in light mode, or the other way round. In practice, a three-way choice works well: system, light and dark. Here is how to approach it:
- Follow the system setting by default.
- Store a manual choice in
localStorage. - Apply the stored choice as a class or attribute on
<html>with a small inline script in the<head>, before the page renders. Otherwise the wrong theme briefly flashes on load. - While "system" is selected, listen for changes to the system setting so that the page follows the automatic switch in the evening.
Keep an eye on loading performance too. Steiner advises against making anyone download CSS in the critical rendering path for a mode they are not currently using. With a few variables this is negligible; with extensive theme stylesheets, splitting them is worthwhile.
Testing: The Most Common Mistakes
Before going live, check at least the following in both modes:
- Measure contrast for links, placeholder text, disabled buttons, error messages and focus outlines, not just body text.
- Look at forms, including autofill backgrounds, date pickers and dropdowns.
- Check embedded content such as maps, videos, cookie banners and chat widgets. They often do not pick up your theme and need their own setting or a suitable frame.
- Review logos, charts and screenshots with transparent backgrounds.
- Test switching the system mode while the page is open.
And on a practical level: read your own website in dark mode for ten minutes, ideally in the evening with dimmed lighting. If your eyes get tired or text seems to shimmer, the contrast or brightness levels are not right yet.
What Dark Mode Delivers, and What It Doesn't
Dark mode can save energy on OLED screens, though less than is often claimed. Researchers at Purdue University measured several OLED smartphones in 2021: at 30 to 50 per cent screen brightness, switching to dark mode saved only 3 to 9 per cent of power on average, while at full brightness it saved 39 to 47 per cent. How page weight and code affect a website's energy use is covered in our article on sustainable web design.
The picture is mixed when it comes to reading comfort, too. According to the research reviewed by the Nielsen Norman Group, some people with cataracts and related conditions read better in dark mode. NN/g therefore recommends letting users switch to dark mode, but not making it the default if a website addresses the general population. In practice, that means following the system setting, offering a toggle and designing both modes with equal care.
Dark mode works best when it is part of the design from the outset. Sidora AG plans colour tokens, contrast and assets for both modes as part of web design and UX design and implements them technically in website development.
Sources
- web.dev (Thomas Steiner): prefers-color-scheme: Hello darkness, my old friend (2019)
- MDN Web Docs: light-dark() (accessed 30 October 2026)
- W3C WAI: Understanding Success Criterion 1.4.3: Contrast (Minimum), WCAG 2.2 (accessed 30 October 2026)
- Google, Material Components for Android: Dark theme (accessed 30 October 2026)
- Nielsen Norman Group (Raluca Budiu): Dark Mode vs. Light Mode: Which Is Better? (2 February 2020)
- Purdue University: Dark mode may not save your phone's battery life as much as you think, but there are a few silver linings (28 July 2021)