{"canonical_url":"https://engineer.company/glossary/contrast-ratio/","content_markdown":"# Contrast ratio\n\n## What it is\n\nA contrast ratio is the single figure, running from 1:1 to 21:1, that WCAG uses to judge whether\ntext, icons and the other visible parts of a page stand out from whatever lies behind them. It\ncompares the luminance of two colours, so it measures a difference in lightness and ignores hue\nentirely. Designers often say colour contrast or luminance contrast, and audits list contrast ratios\nper colour pair; all of these name the same calculation.\n\nThe formula is short. Take the relative luminance of the lighter colour, L1, and of the darker one,\nL2, and divide (L1 + 0.05) by (L2 + 0.05). Relative luminance is normalised to 0 for the darkest\nblack and 1 for the lightest white. For an sRGB colour, each channel is first converted from its\ngamma-encoded value to linear light, and the three are then weighted: 0.2126 for red, 0.7152 for\ngreen and 0.0722 for blue. Two identical colours give 1:1, and black on white gives 21:1.\n\nThose weights are where intuition breaks. Pure green on black measures about 15.3:1, while pure blue\non black manages about 2.4:1, although both look equally vivid. Pure red on white comes out at\n3.998:1. Mid-grey `#767676` on white measures 4.54:1, and `#777777`, one step lighter, measures\n4.48:1. The arithmetic fits in a dozen lines:\n\n```js\n// Contrast ratio of two sRGB colours, as WCAG 2.2 defines it\nconst linear = (c) =\u003e {\n    const s = c / 255;\n    return s \u003c= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;\n};\nconst luminance = (rgb) =\u003e {\n    const [r, g, b] = rgb.map(linear);\n    return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\nconst contrast = (a, b) =\u003e {\n    const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) =\u003e y - x);\n    return (hi + 0.05) / (lo + 0.05);\n};\ncontrast([118, 118, 118], [255, 255, 255]); // 4.54...\n```\n\nIn WCAG 2.2 the ratio is a definition, and four success criteria set thresholds on it:\n\n- **1.4.3 Contrast (Minimum), Level AA:** at least 4.5:1 for text and images of text, and at least\n  3:1 for large-scale text. Text in an inactive control, pure decoration and logotypes carry no\n  contrast requirement.\n- **1.4.6 Contrast (Enhanced), Level AAA:** at least 7:1, and 4.5:1 for large-scale text.\n- **1.4.11 Non-text Contrast, Level AA:** at least 3:1 against adjacent colours for whatever\n  identifies a control and its state, and for the parts of a graphic needed to understand it.\n- **2.4.13 Focus Appearance, Level AAA:** the focus indicator changes by at least 3:1 between the\n  focused and unfocused states across an area at least as large as the control's perimeter drawn 2\n  CSS pixels thick.\n\nLarge-scale text is text of 18 point or more, or of 14 point or more in bold. In CSS pixels that is\n24px, or about 18.7px when bold.\n\n## Why it matters\n\nThe thresholds come from measured vision loss, and knowing their origin helps when someone wants\nto bend them. WCAG's Understanding document starts from 3:1, the minimum an ANSI standard set for\nobservers with typical sight. Vision of 20/40 comes with a loss in contrast sensitivity of roughly\n1.5, so 3 × 1.5 gives 4.5:1, and the same document notes that 20/40 is commonly reported as typical\nacuity at about age 80. The AAA figure of 7:1 compensates for vision around 20/80. Because the\nratio uses luminance alone, it holds up across most colour-vision deficiencies, which hue-based\nrules would not. The same margin helps anyone reading a phone in bright sunlight.\n\nSo the decision a contrast ratio settles is which colours a brand may use for which job, and that\ndecision is far cheaper at the palette than at the page. A brand colour that measures 3.2:1 on white\nstill has work: large headings, icons and the outline of a form field, which need 3:1, backgrounds\nbehind dark text, decoration, the logo itself. What it may not carry is body copy, link text in a\nparagraph or placeholder text, which all need 4.5:1. Deciding that once, in the design tokens, costs\nan afternoon. Finding it after launch means recolouring every component that borrowed the colour,\nand a dark theme doubles the number of pairs to check.\n\nContrast is also one of the few WCAG requirements a machine can verify exactly, provided it knows\nboth colours. That makes it the first finding in most automated audits and the first question on\nmany procurement checklists, and Level AA is the level that accessibility rules and contracts most\noften name. Reaching for AAA's 7:1 everywhere is a choice to weigh: WCAG itself advises against\nrequiring AAA as a policy for entire sites, but 7:1 is a sound target for long reading text where\nthe palette allows it.\n\n## What it looks like in practice\n\nTwo pages on this site show the ratio kept as a recorded number rather than a judgement made by eye.\n\nWhen the site's colour system was closed,\n[each of its 28 colours was documented with the contrast ratio it measures](/portfolio/closed-the-colour-system-at-28-colours/)\non the surface it appears on, and eleven brand values were declared once as tokens. A linter fails\nin five ways, and one of them is a colour recorded with the wrong ratio. The standing rule includes\nnever lowering a documented ratio to make a design work, and a case for a twenty-ninth colour has to\ninclude its ratio. The same page sets a second threshold, a perceptual distance of 0.02 in a uniform\ncolour space, which decides when two spellings are really one colour. That number tells palette\nentries apart; it is a different measure from contrast.\n\nThe harder case was text over a photograph. The work to\n[take WCAG 2.2 Level AA across the site](/portfolio/a-site-that-meets-the-accessibility-standard/)\nincluded replacing a contrast argument with a measurement: the automated rule engine had reported\ntext over the photograph as unevaluable. A measurement rechecked on 2026-09-30 found 49 of 64 page\nand theme pairs below AA on the worst walls in the pool, and two surfaces the design had never\nowned turned out to be the cause. The check that found them is now a floor: every checked pair\nmust carry AA over the wall the build draws, and a pair that falls short fails the build. That is\na contrast check over its sampled scope, rather than proof of complete site-wide AA conformance.\n\n## Where it goes wrong\n\n**Text over a photograph passes in the tool and fails on screen.** WCAG measures text against its\nspecified background and assumes white when none is set. A headline on a hero image has a declared\nbackground that is not the one under its letters, so a checker either measures the wrong pair or\nhands the element back for manual review. Measure against the lightest and darkest pixels the text\ncan sit on at every crop and width, or give the text a solid or scrimmed backing whose colour is\nknown.\n\n**A token measures 4.6:1 and the page shows 3.9:1.** Opacity, `rgba()` text, a translucent overlay\nor a blend mode changes the colour that reaches the screen, so the ratio recorded for the token\ndescribes a colour nobody sees. Compute the ratio of the composited pair, or keep alpha off text\naltogether.\n\n**An audit reports 4.49:1 as a pass.** A ratio shown to one decimal place turns 4.49 into 4.5. The\nUnderstanding document is explicit that the thresholds are not rounded: 4.499:1 does not meet\n4.5:1. Store at least two decimals and compare the raw value with the threshold.\n\n**The light theme is checked and the dark theme ships on trust.** Every theme, and every state a\ncolour can take, is its own pair: hover, focus, visited, error, and placeholder text, which counts\nas text and needs 4.5:1. A disabled control is exempt. Generate the list of pairs from the tokens,\nper theme and per state, and check the list rather than a screenshot.\n\n**Thin type passes on paper and fades on screen.** The ratio comes from the specified colours, but\nanti-aliasing draws hairline weights fainter than their CSS colour, and the Understanding document\nnames this case: such text can pass nominally and still read with much lower contrast. Raise the\nratio for light weights, or choose a heavier cut of the typeface.\n\n## Further reading\n\n- [WCAG 2.2: contrast ratio](https://www.w3.org/TR/WCAG22/#dfn-contrast-ratio) — the normative\n  definition, with its notes on background colour, white as the default and anti-aliasing.\n- [Understanding SC 1.4.3 Contrast (Minimum)](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html)\n  — where 4.5:1 and 3:1 come from, how large-scale text is sized, and why ratios stay unrounded.\n- [Understanding SC 1.4.11 Non-text Contrast](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html)\n  — the 3:1 rule for controls, their states and meaningful graphics, with pass and fail examples.\n- [Understanding SC 1.4.6 Contrast (Enhanced)](https://www.w3.org/WAI/WCAG22/Understanding/contrast-enhanced.html)\n  — the AAA level of 7:1 and the readers it is meant for.\n- [CSS Color Module Level 4](https://www.w3.org/TR/css-color-4/) — the sRGB transfer function and\n  the colour spaces that the luminance formula assumes.\n\n\u003chttps://engineer.company/glossary/contrast-ratio/\u003e\n","date_modified":"2026-11-08T02:22:23Z","description":"How the WCAG contrast ratio is calculated, which thresholds apply to text, icons and focus rings, and where a measured colour pair drifts from the screen.","formats":{"gemtext":"https://engineer.company/glossary/contrast-ratio/index.gmi","gopher":"https://engineer.company/glossary/contrast-ratio/gophermap","html":"https://engineer.company/glossary/contrast-ratio/","json":"https://engineer.company/glossary/contrast-ratio/index.json","markdown":"https://engineer.company/glossary/contrast-ratio/index.md","pdf":"https://engineer.company/glossary/contrast-ratio/index.pdf"},"kind":"page","language":"en","title":"What is a contrast ratio?","url":"https://engineer.company/glossary/contrast-ratio/","version":1}