← All posts

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

PairUsed forRatioBody text
Aa#f2f2f3 on #0a0a0bBody text on the page17.68:1AAA
Aa#f2f2f3 on #141417Body text on a card16.43:1AAA
Aa#8a8a92 on #0a0a0bMuted text on the page5.77:1AA
Aa#8a8a92 on #141417Muted text on a card5.36:1AA
Aa#f6821f on #141417Orange tags on a card7.11:1AAA
Aa#0a0a0b on #f6821fButton label on orange7.66:1AAA

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

Contrast checker

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.