Tweaking One Set of Colors for Light/Dark Modes
Tweaking One Set of Colors for Light/Dark Modes êŽë š
Often when dealing light/dark modes, youâre thinking about entirely changing colors. A light color becomes a dark color and vice versa. Thatâs the nature of the situation!
But think about the oranges. The pinks. The greens and blues. Those are colors that have a decent chance of working OK in both a dark and light theme.
Hereâs the thing:
- If youâve got a pink that looks great on light, it probably should be brightened a bit on dark.
- Or, if youâve got a pink that looks great on dark, it probably should be darkened a bit on light.
An example of something like this is syntax highlighting colors so thatâs what weâll do here. But it could be anything: illustration parts, your <hr />
elment, buttons, whatever.
Hereâs a pink:
.some-tag {
/* pink! */
color: oklch(0.75 0.2 328);
}
Which looks fine on white (and has accessible contrast):

Set it on black, and it still has accessible contrast, and looks⊠also fine.

But I think we could do better. We certainly could have picked a color that didnât meet accessible contrast requirements. But also, I think it would look a bit nicer if that pink was darkened up a smidge on light and lightened up a bit dark.
Fortunately weâve set the color in OKLCH which has perceptually uniform brightness. Meaning if we have a bunch of colors, and we notch them all up in brightness by the same number, they will all appear about the same amount brighter to our human eyes.
A way to approach this is to pick a number of how much we want to bright, darken (or both). Like:
html {
color-scheme: light dark;
--colorAdjuster: -0.1;
@media (prefers-color-scheme: light) {
--colorAdjuster: 0.133;
}
}
Then use this number to adjust our color(s):
.some-tag {
color: oklch(calc(0.75 - var(--colorAdjuster)) 0.2 328);
}
Hereâs an example doing that with syntax highlighting. Youâll need to adjust your color mode preference to see the colors change.
Hereâs both modes as images:
In my opinion, these colors have a very similar feel, but each color, from a base, was darkened a bit in light mode and lightened a bit in dark mode.