Marcus Andrey Study
Ler em português Library

Visual design · Step 3 · 8 min read

Dark mode that actually works

Why inverting your palette breaks dark mode, and how to build a second palette for dark contexts by flipping OKLCH lightness values while keeping chroma and hue constant.

Dark mode is not inverting the colours. It is a second palette that follows the same L rules in OKLCH.

What you'll be able to do after reading:

  • Explain why naïve colour inversion breaks dark mode
  • Flip the L values of a palette to build a dark variant
  • Adjust accent colours for dark surfaces without changing hue
  • Write a dark mode override in CSS using prefers-color-scheme
  • Identify which parts of the Gale Ops palette differ from a simple inversion

1. Why inversion fails

The obvious approach: take every colour in your light palette and invert it. White becomes black, N10 becomes N90, your blue primary at L 0.52 becomes something at L 0.48.

The result looks wrong. There are two reasons.

First, the accent colour problem. Gale Blue at oklch(0.52 0.16 240) works on a white surface because there is enough L distance between 0.52 and 0.97. On a dark surface at L 0.17, L 0.52 looks correct — still readable — but it no longer feels active. The human eye perceives colours on dark backgrounds as lighter and less saturated than they are. To compensate, the accent needs to move to a higher L value.

Second, the semantic colour problem. Status colours at L 0.55 (green), L 0.65 (amber) and L 0.52 (red) pass AA contrast on a white surface (L 0.97). On a dark surface at L 0.17, they may still pass, but they also look washed out. Status colours in a 24/7 control room need to be reliably readable at a glance, often from a distance. That calls for higher chroma, not just a different L.


2. The L inversion model

The model is simple. Take each colour's L value and move it toward the opposite end of the axis — but not by subtraction. The rule is: L high stays high on the light side; L low stays low on the dark side. Flip around a mid-point, then adjust.

Light role Light L Dark role Dark L
Surface (page bg) 0.97 Dark surface (page bg) 0.17
On-surface (text) 0.14 On-surface on dark 0.92
Primary accent 0.52 Primary accent on dark 0.70
Dividers / borders 0.88 Dividers on dark 0.25

Notice that the accent moves from L 0.52 to L 0.70. It is not 1 − 0.52 = 0.48. L 0.48 on a dark surface looks acceptable, but L 0.70 is brighter and reads as more interactive. The chroma stays at C 0.16 and the hue stays at 240°. Only L changes.

The hue stays constant because OKLCH is designed so that hue-shift does not happen when L or C changes. In HSL, shifting the lightness of a blue often produces a subtle hue drift toward purple or cyan. In OKLCH it does not — which is exactly why this model works.


3. Gale Ops: the dark palette

The same component in Gale Console (light) and Gale Ops (dark). The structure and semantic roles are identical. What changes is the L value: surfaces go from 0.97 to 0.17, text from 0.14 to 0.92, the accent from 0.52 to 0.70. Chroma (C) and hue (H) stay the same — only L is flipped. Diagram: Marcus Andrey, CC BY 4.0.

Gale Ops is the wall-screen dashboard for the control room. It runs in dark mode by default, 24 hours a day. These are its surface values:

/* Gale Ops — dark palette */
:root[data-theme="dark"] {
  --color-surface:          oklch(0.17 0.015 240);  /* primary surface */
  --color-surface-base:     oklch(0.12 0.015 240);  /* page base, behind cards */
  --color-surface-raised:   oklch(0.22 0.015 240);  /* elevated surface */
  --color-on-surface:       oklch(0.92 0.01 240);   /* primary text */
  --color-on-surface-muted: oklch(0.65 0.015 240);  /* secondary text */
  --color-border:           oklch(0.25 0.015 240);  /* dividers */

  /* Accent — higher L on dark */
  --color-primary:          oklch(0.70 0.14 240);
  --color-on-primary:       oklch(0.12 0.015 240);  /* dark text on light accent */
  --color-secondary:        color-mix(in oklch, oklch(0.70 0.14 240) 15%, transparent);

  /* Status — same hue, slightly higher L and chroma for visibility at distance */
  --color-success:          oklch(0.72 0.17 145);
  --color-warning:          oklch(0.78 0.16 70);
  --color-danger:           oklch(0.68 0.20 25);
  --color-info:             oklch(0.70 0.14 240);
}

A few things to notice:

  • The base background is at L 0.12, not L 0.17. L 0.12 is the page base — the colour that fills the space between cards. The card surface sits at L 0.17, one step above the base.
  • The status colours are higher in both L and chroma than their light-mode equivalents. They need to read clearly at a distance, on a wall screen, in a dimly lit room.
  • --color-on-primary is a dark colour on the light accent. On a surface at L 0.70, dark text (L 0.12) passes AAA against the accent.

4. The CSS implementation

The cleanest approach is to define all roles in the :root as the light values, then override them inside a prefers-color-scheme: dark media query and optionally inside a [data-theme="dark"] attribute selector. This gives you:

  • Automatic mode from the OS setting
  • A manual override via JavaScript (the data attribute)
  • One set of semantic tokens the rest of the CSS uses, never the palette values directly
/* Base: light mode */
:root {
  --color-surface:    oklch(0.97 0.01 240);
  --color-on-surface: oklch(0.14 0.015 240);
  --color-primary:    oklch(0.52 0.16 240);
  /* ... */
}

/* Dark mode — OS preference */
@media (prefers-color-scheme: dark) {
  :root {
    --color-surface:    oklch(0.17 0.015 240);
    --color-on-surface: oklch(0.92 0.01 240);
    --color-primary:    oklch(0.70 0.14 240);
    /* ... */
  }
}

/* Dark mode — manual override */
:root[data-theme="dark"] {
  --color-surface:    oklch(0.17 0.015 240);
  --color-on-surface: oklch(0.92 0.01 240);
  --color-primary:    oklch(0.70 0.14 240);
  /* ... */
}

One thing to avoid: setting colours directly on individual components (.card { background: oklch(0.97 0.01 240) }). When you need to change that colour for dark mode, you have to find every component that hardcodes it. If the component uses --color-surface instead, the dark mode override applies automatically.


5. What about images and illustrations

Images do not adapt automatically to dark mode. A product screenshot with a white background, embedded in a dark card, looks like a light box — it draws the eye for the wrong reason.

Three options, in order of effort:

  1. Dark-mode versions of the images (accurate but expensive to maintain).
  2. filter: brightness(0.9) on images in dark mode — reduces the harshness slightly.
  3. Display images on a neutral-coloured surface — a card with a slightly lighter surface (L 0.22) contains the image without the full contrast clash and avoids placing it directly on the dark background.

For Gale Ops, the main concern is not images but charts and data visualisations. Dark mode charts need data series colours that work on dark surfaces. The same OKLCH L-flip rule applies: move the series colours to higher L values, same C and H.

Palette and dark mode are ready. Now: how do you measure whether the contrast is enough for text to be readable?


6. Common mistakes

  • Inverting by subtraction. L_dark = 1 − L_light produces mathematically symmetrical values but perceptually unbalanced results. The accent at L 0.48 on a dark surface looks flat. Move it to L 0.70 instead.
  • Forgetting the base layer. A dark palette needs at least two distinct L values for surfaces: the page base and the card surface. Without the separation, there is no depth — everything looks like one flat plane.
  • Using the same status colours in light and dark. The green at L 0.55 that looks good on a white surface may read as dull on a surface at L 0.17. Test status colours in both contexts.
  • Using opacity to simulate the dark variant. opacity: 0.8 on a black overlay does not produce the same result as a proper dark palette. Opacity-based "dark mode" shows through to the page background and breaks in layered contexts.
  • No manual override. prefers-color-scheme follows the OS. If the user wants to switch without changing their OS setting — a common request in tools people use all day — they need a toggle backed by a data attribute.

7. Try it

Use the light and dark comparison in the figure above. The same card is shown in Gale Console (light) and Gale Ops (dark).

  1. Look at the L values listed below each card. The surface goes from 0.97 (light) to 0.17 (dark). The text goes from 0.14 to 0.92. Write the formula you used: how did you calculate the dark L from the light L? Is it subtraction? A fixed offset? Something else?
  2. Notice the accent. Light mode: L 0.52. Dark mode: L 0.70. That is not a simple inversion. If you used L 0.48 (the subtraction result) instead, what would change? Open the CSS.land OKLCH tool and compare oklch(0.52 0.16 240) on white and oklch(0.48 0.16 240) on oklch(0.17 0.015 240). Does 0.48 have more or less contrast?
  3. Write the CSS dark mode override for two tokens: --color-surface and --color-primary. Use both @media (prefers-color-scheme: dark) and [data-theme="dark"].

You are done when you can write the override with the correct L values from memory.


8. If you already practise

  • A common request is "dark mode where only the background is dark, the accent stays the same." Try this for Gale Blue: keep C 0.16 and H 240, but test L values from 0.50 to 0.70 against a dark surface at L 0.17. What is the minimum L that passes WCAG AA?
  • The color-scheme CSS property (MDN) tells the browser to adapt native form controls and scrollbars to the colour scheme. Without it, a custom dark background shows dark-mode custom inputs alongside light-mode browser inputs.
  • Read the GOV.UK Design System's approach to dark mode (design-system.service.gov.uk) and compare their palette decisions with Gale's.

Checklist


Learn more

Books, courses and videos to go deeper

Book links go to Amazon. As an Amazon Associate I earn from qualifying purchases, at no extra cost to you.


Semantic colour and state · Contrast ratios and WCAG · Building a colour palette in OKLCH

Saved only on this device.

↑ ↓ to move · Enter to open · Esc to close