The formula
contrast = (L1 + 0.05) ÷ (L2 + 0.05)
Where it comes from
Relative luminance is not apparent brightness: each channel is corrected by a curve and weighted by the eye's sensitivity, which is far greater to green than to blue. That is why a bright yellow and a deep blue can have contrasts quite unlike what the eye expects.
How to work it out by hand
- Work out the relative luminance of each colour
- Add 0.05 to each
- Divide the larger by the smaller
- Compare against the thresholds: 4.5 for AA and 7 for AAA
What is worth knowing
Level AA at 4.5:1 is the minimum worth aiming at and the one public sector websites are held to in the EU and, in practice, under the accessibility rules of the UK, the US and Australia. Large text, from 18 point or 14 point bold, gets by on 3:1 because the strokes are thicker. The maximum possible contrast is 21:1, pure white on pure black.