Is this grey readable?
A small WCAG contrast checker, and an honest look at the colours of this very blog.
This blog is dark: near-black background, off-white text, and a grey for everything that should step back a little. Dark themes make it easy to pick a grey that looks calm on a good monitor and turns to mush on a cheap laptop in sunlight. So before writing anything else here, I wanted to check my own colours.
How contrast is measured
WCAG defines contrast as a ratio between the relative luminance of two colours, from 1:1 (identical) to 21:1 (black on white). Luminance is not the average of the RGB values: each channel is first converted from sRGB back to linear light, then weighted by how sensitive our eyes are to it. Green counts for about 72 %, red 21 %, blue only 7 %.
const channel = (v: number) => {
const s = v / 255;
return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
};
const luminance = ([r, g, b]: RGB) =>
0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
const contrast = (a: RGB, b: RGB) => {
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
return (hi + 0.05) / (lo + 0.05);
};
The thresholds: 4.5:1 for body text and 3:1 for large text and UI parts to pass level AA; 7:1 and 4.5:1 for AAA.
This blog’s palette
| Pair | Used for | Ratio | Body text |
|---|---|---|---|
Aa#f2f2f3 on #0a0a0b | Body text on the page | 17.68:1 | AAA |
Aa#f2f2f3 on #141417 | Body text on a card | 16.43:1 | AAA |
Aa#8a8a92 on #0a0a0b | Muted text on the page | 5.77:1 | AA |
Aa#8a8a92 on #141417 | Muted text on a card | 5.36:1 | AA |
Aa#f6821f on #141417 | Orange tags on a card | 7.11:1 | AAA |
Aa#0a0a0b on #f6821f | Button label on orange | 7.66:1 | AAA |
The grey passes AA on both backgrounds, with a bit of room to spare. Orange on a card also passes, which is why tags can be orange. The dark label on the orange button does fine too.
Try your own colours
Large text, 24px
Body text at 16px. The quick brown fox jumps over the lazy dog.
5.77:1 contrast
- AA body text4.5:1 passes
- AA large text & UI3:1 passes
- AAA body text7:1 fails
- AAA large text4.5:1 passes
Pick colours or type hex values. If a pair fails, the checker suggests the nearest text colour that passes, keeping the hue and only moving it towards white or black. Everything runs in your browser; nothing is sent or stored.
What the numbers don’t tell you
Contrast ratio is a floor, not a guarantee. Thin font weights, small sizes and light-on-dark text (which tends to bloom a little) all read worse than the ratio suggests. The newer APCA model used in drafts of WCAG 3 accounts for some of that. For now, 4.5:1 with a regular weight is a good default, and it’s nice to know the grey here clears it.