The neighbourhood head’s kerja bakti notice in a light and a dark theme: type any CSS colour, the browser computes it (see-through ones included), and the…
Why it matters
Low contrast = text unreadable for low-vision users, older people and anyone in the sun. AA (4.5:1) is often an audit and legal requirement. Knowing how it is worked out makes colour choices you can defend, not guesses, in every theme.
The key idea
Contrast is a luminance ratio, not a difference in colour
Common mistakes
Thinking "the colours differ" means enough contrast Two colours can differ plainly in hue yet sit close in luminance, e.g. red #ff0000 on green #008000 is only about 1.3:1. Luminance counts, not hue. Measure, do not guess.
A light-grey placeholder or caption fails AA The most common AA failure. Darken it to at least 4.5:1, or make it bigger/bolder until it counts as large text (3:1).
Forgetting large text has another threshold 24px and up (or 18.66px bold and up) only needs 3:1 for AA. Headings may use a softer colour than body text.
Checking contrast in the light theme only Dark mode has another background, so another ratio: the #2563eb link passes on white (5.2:1) yet fails on #0f172a (3.4:1). Give each theme its own colours and measure both.
Try it in this playground
Type your own text colour until the light grey passes AA Darken it bit by bit and watch the luminance drop and the ratio climb past 4.5.
Slide font-size to 24px while the ratio is between 3 and 4.5 The ratio stays, yet the threshold drops to 3:1: it passes as large text.
Open One colour, two themes The same colour passes in one theme and fails in the other: the ratio is against its background.
Use a see-through colour, e.g. rgb(0 0 0 / 0.5) Look at the "painted" row: the colour counted is the mix with the background.