WCAG Contrast Ratios: The Math Behind the 4.5:1 Rule
#767676 on white is 4.54:1 and passes WCAG AA. #777777, one step lighter, is 4.48:1 and fails. Nobody can see that difference on a screen. An audit can, and it will list every text style you built on that gray.
Contrast is the cheapest accessibility fix and the one teams get wrong most often, because the rule is arithmetic and the judgment is visual. Here is the arithmetic.
The formula, without the hand-waving
WCAG 2.x defines contrast as (L1 + 0.05) / (L2 + 0.05), where L is the relative luminance of the lighter and the darker color. Luminance is not brightness, and it is not HSL lightness. Each sRGB channel is linearized first:
c = channel / 255
c_lin = c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ^ 2.4
L = 0.2126 * R + 0.7152 * G + 0.0722 * B
Green carries 71% of the weight. That single coefficient explains most of the surprises. Pure green (#00FF00) on white is 1.37:1 — the brightest color on the wheel and unreadable as text. Pure red (#FF0000) on white is 4.00:1, which fails normal text but passes large text. Brand colors chosen in a moodboard do not survive this math.
Two tiers, and what each one covers
- 4.5:1 for normal text (1.4.3).
- 3:1 for large text: 24px regular or 18.66px bold, and anything above that.
- 3:1 for UI components and meaningful graphics (1.4.11): input borders, toggle states, icon-only buttons, chart lines that carry data.
Two exemptions get abused. Logos have no contrast requirement at all. Disabled controls are exempt from 1.4.3 — but exempt means a checker will not flag it, not that a user can read it. Gray-on-gray disabled buttons at 1.6:1 are a support ticket, not a compliance win.
Where it actually breaks
Placeholder text. It is text, and it is subject to 4.5:1. Browser defaults in most engines land near 3:1 on white, which is why placeholder-only forms fail audits and confuse users at the same time.
Hover and focus states. Teams check the default state, ship, and never check the other four. A link at 5.2:1 that drops to 3.1:1 on hover still fails, and the hover state is where the user's cursor actually is.
Text over images. A gradient hero with white text has a different ratio at every pixel. The number that matters is the worst pixel under the glyph, not the average. Measure the lightest region, not the middle.
Opacity. color: #333; opacity: 0.6 is not #333. It composites against whatever sits behind it: effective = alpha * foreground + (1 - alpha) * background. At 0.6 over white, #333 becomes roughly #858585 — 3.4:1, a failure that never appears in your token file.
The five-minute test that catches most of it
- Open the page at 100% zoom with no devtools color overrides.
- Screenshot it and sample the rendered pixels with an eyedropper, not the hex from Figma. Font smoothing, blending and image backgrounds all change the real value.
- Paste both colors into a contrast checker and write the ratio next to the component name.
- Repeat for hover, focus, active, visited and disabled.
- Check icon-only buttons and input borders against 3:1 instead of 4.5:1.
If a color sits close to the line, convert it first. Small rounding differences between HEX, RGB and HSL move the ratio by a few hundredths, and that is enough to flip a pass into a fail. The color converter gives you the exact channel values the formula expects, and the luminance calculator shows the intermediate number so you can see why a color fails instead of guessing at it.
Fixing without redesigning
Move one color, not both. Keeping the background and pushing the text toward the foreground preserves the design intent and changes a single token. A gray at 4.48:1 needs about 2% more darkness to cross 4.5:1 — usually one step on an existing palette.
For text over photography, add a scrim instead of a heavier font weight. A black overlay at 40% over a mid-tone photo puts white text comfortably past 7:1 and reads as a design decision rather than a patch.
Do not fix contrast by making everything black. 7:1 (AAA) is the target for body copy in reading-heavy interfaces, not for every caption and label. Overcorrecting flattens hierarchy, and hierarchy is what makes a dense interface scannable in the first place.
What the ratio does not measure
Contrast compares two solid colors. It says nothing about color blindness — a red/green pair can hit 6:1 and still be indistinguishable to roughly 8% of men. Run the palette through a color blindness simulator before you let color alone carry meaning, and pair it with an icon, a label, or position.
It also says nothing about font weight. A 300-weight 14px text at exactly 4.5:1 reads worse than a 500-weight at 4.2:1. The spec is a floor, not a design review.
WCAG 3 will replace the ratio with APCA, which accounts for font size, weight and polarity. It is still a draft. Until it ships, 4.5:1 and 3:1 are what auditors, procurement forms and the European Accessibility Act reference — EN 301 549 points straight back at WCAG 2.1 AA.
Run the numbers on your five most-used text styles today. In most codebases one of them fails, and the fix is a one-line change to a design token.