# Designing websites for dark mode

Design for dark mode by following the visitor's system setting with the prefers-color-scheme media feature, declaring color-scheme so browser controls match, and building a separate dark palette that you test against WCAG contrast ratios. Dim photos slightly, provide logo and icon versions that work on dark backgrounds, and load the right theme before the page paints so visitors never see a bright flash.


## How dark mode on the web works

A website supports dark mode when it detects the visitor's system preference and switches to a dark colour palette designed for it. Browsers expose that setting through the [prefers-color-scheme media feature](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme), which reports light or dark. Your stylesheet uses it to swap colours, and the color-scheme property tells the browser to style its own controls to match. Good dark mode is a second design with its own tested colours.

Plenty of people now run their phones and laptops in dark mode all day. A site that stays bright white at night can feel jarring, and a poorly made dark theme with grey-on-grey text is worse. The steps below cover both the design and the build.


## Decide how the theme gets chosen

Follow the system setting by default. Google's web.dev article on [prefers-color-scheme](https://web.dev/articles/prefers-color-scheme) recommends respecting the operating system preference and optionally letting visitors override it with a toggle. If you add a toggle, remember the choice so it survives a page change, and offer three states: light, dark and match system.


### Declare color-scheme first

The [color-scheme property](https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme) tells the browser which themes your page supports, so it can render form fields, scrollbars and other built-in elements in matching colours. Set it on the root element with the value light dark. Without it, you can end up with a dark page full of bright white input boxes.


### Use light-dark() to keep stylesheets small

The CSS [light-dark() function](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark) takes two colours and returns the first in light mode and the second in dark mode, without a separate media query. MDN lists it as widely available across browsers since May 2024, and notes it only works when color-scheme is set to light dark. Pair it with named colour variables such as surface, text and accent so the meaning stays the same in both themes.


## Build a dark palette that works

Inverting your light theme produces harsh results. Build the dark palette as its own set of decisions.

Start with three or four surface levels: the page background, cards, raised panels and overlays. In a light theme, depth often comes from shadows. In a dark theme, shadows barely show, so raised elements usually get a slightly lighter surface colour instead. Then set text colours for primary, secondary and disabled states, and finally adjust your accent colour until buttons and links pass contrast on every surface they sit on.

| Element | Light theme habit | Dark theme approach |
|---|---|---|
| Background | White | Very dark grey or a dark tint of your brand colour |
| Body text | Near black | Off-white, slightly softer than pure white |
| Brand accent | Full saturation | Often a lighter, less saturated version for contrast |
| Borders and dividers | Light grey | Subtle lighter lines, or spacing instead of lines |
| Shadows | Drop shadows for depth | Lighter surfaces for raised elements |

web.dev suggests avoiding pure white text on dark backgrounds, because it can appear to glow and bleed. A slightly off-white reads more comfortably for long paragraphs.

Keep saturated colours for small accents. Large blocks of bright brand colour on a dark page are tiring to look at, and they pull attention away from the content. If your brand relies on a strong colour, use it for buttons, links and highlights, and let the dark surfaces carry the rest of the page.


### Check contrast in both themes

The W3C's guidance on [contrast (minimum)](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html) asks for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text. That applies to your dark theme as much as your light one. Brand colours that pass on white often fail on dark grey, especially reds and blues, so test every text and button colour pair in a contrast checker.


#### Contrast checks people forget

- Placeholder text and helper text inside form fields.
- Links inside body text, which need to stand out from surrounding text too.
- Focus outlines, which can disappear against dark surfaces.
- Text on top of images or video in hero sections.
- Error and success messages that rely on red and green.


## Handle images, logos and icons

Photos can look too bright in a dark interface. web.dev describes dimming photos slightly in dark mode with a CSS filter, and swapping major images with the picture element when a dedicated dark version works better. Compressed modern formats keep both versions light; see our guide to [image optimization and WebP](https://tcomconsultants.com/blog/image-optimization-webp/).

1. Create a logo version for dark backgrounds, often a light or reversed lockup.
2. Use SVG icons that inherit the text colour so they switch automatically.
3. Avoid transparent PNG logos with dark text that vanish on dark pages.
4. Check charts and diagrams, which often hard-code white backgrounds.

Your logo is part of your identity, so plan the dark version when the brand is created. Our guide to [building a brand identity for a small business](https://tcomconsultants.com/blog/brand-identity-small-business/) covers logo variations.


## Avoid the flash and test properly

A bright flash before the dark theme loads is the most common complaint about dark mode on websites. Put the theme colours in CSS that loads in the head, and if you use a saved toggle preference, apply it with a tiny inline script before the page renders. web.dev also advises against making visitors download CSS for a theme they are not using in the critical rendering path.

Test every page template in both themes on a real phone at night. Look at forms, tables, embedded maps and third-party widgets, which often ignore your theme. Transitions between themes should be quick and simple; our guide to [motion design on websites](https://tcomconsultants.com/blog/motion-design-on-websites/) explains how to keep animation light. Dark mode is one of several current design shifts covered in our [web design trends for 2026](https://tcomconsultants.com/blog/web-design-trends/).


## How Tcom can help

We build sites with tested light and dark themes as part of our [website development service](https://tcomconsultants.com/services/website-development/), and we keep structured data and content identical across both, as described in our answer on [schema markup for small businesses](https://tcomconsultants.com/answers/schema-markup-for-small-business/). See [our work](https://tcomconsultants.com/work/) or [contact us](https://tcomconsultants.com/contact/) to add dark mode to your site.

## Sources

- prefers-color-scheme (MDN Web Docs): https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
- color-scheme (MDN Web Docs): https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme
- light-dark() (MDN Web Docs): https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark
- prefers-color-scheme: Hello darkness, my old friend (web.dev (Google)): https://web.dev/articles/prefers-color-scheme
- Understanding Success Criterion 1.4.3: Contrast (Minimum) (W3C Web Accessibility Initiative): https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html

Source: https://tcomconsultants.com/blog/dark-mode-web-design/
