Sub topic 9
Designing a dark palette that is comfortable to read
This chapter assumes you can write CSS custom properties, know the prefers-color-scheme media query, and have already defined semantic color tokens such as --bg and --text. Here you decide which values those tokens should hold in dark mode.
Why inverting colors fails
A common first attempt is to swap white and black. Pure black (#000000) with pure white (#ffffff) text gives the highest possible contrast. On many screens it is also tiring to read. Bright text on a very dark field tends to look like it glows or blurs, and the effect is stronger for people with astigmatism.
Saturated colors also behave differently. A vivid blue that works on white can vibrate against a dark background. Dark mode needs its own values, not the light values flipped.
Start with the background
Use a very dark gray instead of pure black. Values near #121212 are a widely used starting point. A tinted gray, such as a dark blue-gray, can give the page a more intentional look.
Then use slightly lighter grays for raised surfaces such as cards, menus, and dialogs. In light mode, shadows show that something sits above the page. Shadows are hard to see on dark backgrounds, so lighter surfaces take over that job.
:root {
color-scheme: light dark;
--bg: #ffffff;
--surface: #f4f5f7;
--text: #1a1a1a;
--text-muted: #5b6270;
--accent: #0b5fff;
--border: #d5d8de;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #121212;
--surface: #1e1e22;
--text: #e6e6e6;
--text-muted: #a3a8b3;
--accent: #8ab4ff;
--border: #34363d;
}
}
body {
background: var(--bg);
color: var(--text);
}
.card {
background: var(--surface);
border: 1px solid var(--border);
}
.card .meta {
color: var(--text-muted);
}Soften the text
Use off-white text, such as #e6e6e6, for body copy instead of #ffffff. This lowers glare while keeping contrast high. Reserve brighter white for small amounts of emphasis, such as headings.
Keep a separate muted text token for secondary content. In dark mode, muted text must still pass contrast checks, so do not make it too dim.
Adjust accent colors
Light-mode accents are usually too dark for a dark background. Pick lighter, slightly less saturated versions for dark mode. In the example above, the link color changes from #0b5fff to #8ab4ff. It keeps the same hue, so the brand still feels consistent, but it is lighter and easier to read.
Apply the same rule to status colors (error, success, warning). A red that reads well on white often needs to become a lighter, softer red on a dark surface.
Think in lightness steps
It helps to treat each theme as a ramp of lightness levels instead of a list of unrelated hex codes.
| Role | Light theme | Dark theme |
|---|---|---|
| Page background | Lightest | Darkest |
| Raised surface | Slightly darker than page | Slightly lighter than page |
| Border | Mid-light | Mid-dark |
| Muted text | Mid-dark | Mid-light |
| Body text | Darkest | Lightest, but off-white |
Notice that the elevation direction reverses. In light mode, raised surfaces get darker or gain a shadow. In dark mode, they get lighter.
Common mistakes
- Using pure black with pure white text, which causes glare.
- Reusing light-mode accent colors, which look dim or vibrate on dark backgrounds.
- Leaving borders unchanged. A light border on a dark card looks harsh, so give borders their own token.
- Making muted text too dark, so it fails contrast requirements.
- Choosing colors by eye on one monitor. Check them on a second screen and at different brightness settings.
The next chapter covers how to measure contrast so that these choices can be checked against numbers instead of only by eye.
Exercise
A card in your dark theme uses --surface: #121212, the same value as the page background --bg. The card's border is #d5d8de, copied from the light theme. Name two problems and give a fix for each.
Show answer
First, the card has the same color as the page, so nothing shows that it is raised. Fix it by making the surface slightly lighter, for example #1e1e22. Second, the light border is too bright on a dark surface and looks harsh. Fix it by giving the border a dark-theme value, for example #34363d, through its own token.
Exercise
Why should the dark theme's --accent usually differ from the light theme's --accent?
Show answer
A dark accent color has low contrast against a dark background. A lighter, slightly less saturated version of the same hue stays readable and still matches the brand.