{"course":{"slug":"design-foundations","title":"Design, before Any Software","url":"https://addaly.com/learn/design-foundations","level":"beginner","track":"create"},"lesson":{"slug":"the-contrast-ratio-formula","title":"What a contrast checker is actually computing","url":"https://addaly.com/learn/design-foundations/the-contrast-ratio-formula","position":37,"of":74,"minutes":9,"answer":"Linearise the sRGB channels, find each colour’s relative luminance, and compare the unrounded ratio for the actual foreground and background.","keyIdea":"Linearise the sRGB channels, find each colour’s relative luminance, and compare the unrounded ratio for the actual foreground and background."},"body":{"format":"markdown","text":"## From screen values to relative luminance\n\nThe [WCAG 2.2 contrast ratio](https://www.w3.org/TR/WCAG22/#dfn-contrast-ratio) for sRGB colours ranges from 1:1 to 21:1. The formula compares two relative luminances. Colour values such as an RGB channel of 128 must be converted before they can represent light.\n\nDivide each 8-bit red, green and blue channel by 255. Apply the [WCAG sRGB conversion](https://www.w3.org/TR/WCAG22/#dfn-relative-luminance) separately to each result.\n\n```\nc_lin = c / 12.92                  when c <= 0.04045\nc_lin = ((c + 0.055) / 1.055)^2.4   otherwise\n```\n\nThe published cutoff is 0.04045. Some older references show 0.03928. Then apply the luminance weights and compare the lighter and darker luminances.\n\n```\nL = 0.2126 × R_lin + 0.7152 × G_lin + 0.0722 × B_lin\nratio = (L_lighter + 0.05) / (L_darker + 0.05)\n```\n\nBlack against white gives 1.05 divided by 0.05, or 21:1. Identical colours give 1:1, including black against black. The 0.05 term is fixed. The checker never measures the light falling on your screen.\n\n## Compare the ratio with the right threshold\n\nFor [Contrast (Minimum), level AA](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html), ordinary text needs 4.5:1 and large text needs 3:1, subject to the criterion's exceptions. Large text is at least 18 points or 14 points bold. That is 24 CSS pixels or about 18.67 CSS pixels bold.\n\n[Contrast (Enhanced), level AAA](https://www.w3.org/WAI/WCAG22/Understanding/contrast-enhanced.html) uses 7:1 for ordinary text and 4.5:1 for large text. [Non-text Contrast, level AA](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html) uses 3:1 against adjacent colours for visual information needed to identify controls and states, and for parts of graphics needed to understand them. Check the cue that carries information. A border that only decorates an already identifiable control is a different case.\n\n> Figure: How to check a contrast ratio. Steps: 1. Linearise (Convert each sRGB channel using the 0.04045 cutoff.); 2. Weight and sum (Multiply red by 0.2126, green by 0.7152 and blue by 0.0722.); 3. Take the ratio (Add 0.05 to each luminance and divide the larger by the smaller.); 4. Compare (Use the unrounded result and the threshold for that use.). Identical colours produce 1:1. Black and white produce 21:1. Use the colours from the actual foreground and background.\n\n## Work through one pair\n\nFor `#808080`, each channel is 128 divided by 255, about 0.502. The power formula gives about 0.216. The channel weights sum to 1, so the grey's relative luminance is also about 0.216. On white, the contrast is about 3.95:1. That passes the AA large-text threshold. Use a darker grey for ordinary text.\n\nWith opaque neutral greys on white, `#767676` gives 4.542:1 and `#777777` gives 4.478:1. The first passes 4.5:1. For the 3:1 threshold, `#949494` gives about 3.033:1 and `#959595` gives about 2.995:1. A checker that displays two decimal places might round the second to 3.00. Make the pass decision from the unrounded value.\n\n## Check the actual background\n\nOpacity changes the colour you see. For a simple sRGB example, black text at 55% opacity over white gives about 4.76:1 before rounding the resulting channels to 8-bit values. Place the same text on `#dddddd` and it gives about 4.39:1. This crosses the ordinary-text threshold. Check the composited colours in each state. For text over an image or gradient, check the least favourable part the text crosses, or give the text a solid backing.\n\nTry two adjacent grey swatches with a checker. Save the foreground and background values, the unrounded ratio and the criterion you checked. Then increase the difference enough that the result stays clear on a small phone in bright light."},"check":{"question":"Black text at 55% opacity measures about 4.76:1 on white and 4.39:1 on a grey card. Why can the same text pass the AA ordinary-text threshold in one place and fail in the other?","options":[{"text":"The text is composited with each background, so its rendered colour and contrast change.","correct":true},{"text":"The browser makes the font smaller whenever the background becomes grey.","correct":false,"tempting":"The example keeps the text styling fixed and changes the background only."},{"text":"AA requires more contrast for text on grey backgrounds than on white.","correct":false,"tempting":"The threshold is the same for ordinary text in both places."},{"text":"The 0.05 term changes automatically with each page background.","correct":false,"tempting":"The 0.05 term is fixed for both calculations."}]},"prev":{"slug":"why-hsl-lies-about-lightness","title":"The lightness slider is not lightness","url":"https://addaly.com/learn/design-foundations/why-hsl-lies-about-lightness"},"next":{"slug":"where-contrast-ratios-fail","title":"Where the contrast standard is wrong, and what is unsettled","url":"https://addaly.com/learn/design-foundations/where-contrast-ratios-fail"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'What a contrast checker is actually computing', in Design, before Any Software. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/design-foundations/the-contrast-ratio-formula (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"What a contrast checker is actually computing","courseTitle":"Design, before Any Software","module":{"index":4,"slug":"colour-measured","title":"Colour, measured"},"answer":null,"keyIdea":"Linearise the sRGB channels, find each colour’s relative luminance, and compare the unrounded ratio for the actual foreground and background.","hero":{"kind":"figure","figure":{"t":"figure","label":"Figure","figure":{"type":"flow","title":"How to check a contrast ratio","steps":[{"label":"Linearise","detail":"Convert each sRGB channel using the 0.04045 cutoff."},{"label":"Weight and sum","detail":"Multiply red by 0.2126, green by 0.7152 and blue by 0.0722."},{"label":"Take the ratio","detail":"Add 0.05 to each luminance and divide the larger by the smaller."},{"label":"Compare","detail":"Use the unrounded result and the threshold for that use."}],"caption":"Identical colours produce 1:1. Black and white produce 21:1. Use the colours from the actual foreground and background."},"alt":"Figure: How to check a contrast ratio. Steps: 1. Linearise (Convert each sRGB channel using the 0.04045 cutoff.); 2. Weight and sum (Multiply red by 0.2126, green by 0.7152 and blue by 0.0722.); 3. Take the ratio (Add 0.05 to each luminance and divide the larger by the smaller.); 4. Compare (Use the unrounded result and the threshold for that use.). Identical colours produce 1:1. Black and white produce 21:1. Use the colours from the actual foreground and background."}},"blocks":[{"t":"h2","id":"from-screen-values-to-relative-luminance","runs":[{"text":"From screen values to relative luminance"}]},{"t":"p","runs":[{"text":"The "},{"text":"WCAG 2.2 contrast ratio","href":"https://www.w3.org/TR/WCAG22/#dfn-contrast-ratio"},{"text":" for sRGB colours ranges from 1:1 to 21:1. The formula compares two relative luminances. Colour values such as an RGB channel of 128 must be converted before they can represent light."}]},{"t":"p","runs":[{"text":"Divide each 8-bit red, green and blue channel by 255. Apply the "},{"text":"WCAG sRGB conversion","href":"https://www.w3.org/TR/WCAG22/#dfn-relative-luminance"},{"text":" separately to each result."}]},{"t":"code","lang":"","label":"Text","text":"c_lin = c / 12.92                  when c <= 0.04045\nc_lin = ((c + 0.055) / 1.055)^2.4   otherwise"},{"t":"p","runs":[{"text":"The published cutoff is 0.04045. Some older references show 0.03928. Then apply the luminance weights and compare the lighter and darker luminances."}]},{"t":"code","lang":"","label":"Text","text":"L = 0.2126 × R_lin + 0.7152 × G_lin + 0.0722 × B_lin\nratio = (L_lighter + 0.05) / (L_darker + 0.05)"},{"t":"p","runs":[{"text":"Black against white gives 1.05 divided by 0.05, or 21:1. Identical colours give 1:1, including black against black. The 0.05 term is fixed. The checker never measures the light falling on your screen."}]},{"t":"h2","id":"compare-the-ratio-with-the-right-threshold","runs":[{"text":"Compare the ratio with the right threshold"}]},{"t":"p","runs":[{"text":"For "},{"text":"Contrast (Minimum), level AA","href":"https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html"},{"text":", ordinary text needs 4.5:1 and large text needs 3:1, subject to the criterion’s exceptions. Large text is at least 18 points or 14 points bold. That is 24 CSS pixels or about 18.67 CSS pixels bold."}]},{"t":"p","runs":[{"text":"Contrast (Enhanced), level AAA","href":"https://www.w3.org/WAI/WCAG22/Understanding/contrast-enhanced.html"},{"text":" uses 7:1 for ordinary text and 4.5:1 for large text. "},{"text":"Non-text Contrast, level AA","href":"https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html"},{"text":" uses 3:1 against adjacent colours for visual information needed to identify controls and states, and for parts of graphics needed to understand them. Check the cue that carries information. A border that only decorates an already identifiable control is a different case."}]},{"t":"h2","id":"work-through-one-pair","runs":[{"text":"Work through one pair"}]},{"t":"p","runs":[{"text":"For "},{"text":"#808080","code":true},{"text":", each channel is 128 divided by 255, about 0.502. The power formula gives about 0.216. The channel weights sum to 1, so the grey’s relative luminance is also about 0.216. On white, the contrast is about 3.95:1. That passes the AA large-text threshold. Use a darker grey for ordinary text."}]},{"t":"p","runs":[{"text":"With opaque neutral greys on white, "},{"text":"#767676","code":true},{"text":" gives 4.542:1 and "},{"text":"#777777","code":true},{"text":" gives 4.478:1. The first passes 4.5:1. For the 3:1 threshold, "},{"text":"#949494","code":true},{"text":" gives about 3.033:1 and "},{"text":"#959595","code":true},{"text":" gives about 2.995:1. A checker that displays two decimal places might round the second to 3.00. Make the pass decision from the unrounded value."}]},{"t":"h2","id":"check-the-actual-background","runs":[{"text":"Check the actual background"}]},{"t":"p","runs":[{"text":"Opacity changes the colour you see. For a simple sRGB example, black text at 55% opacity over white gives about 4.76:1 before rounding the resulting channels to 8-bit values. Place the same text on "},{"text":"#dddddd","code":true},{"text":" and it gives about 4.39:1. This crosses the ordinary-text threshold. Check the composited colours in each state. For text over an image or gradient, check the least favourable part the text crosses, or give the text a solid backing."}]},{"t":"p","runs":[{"text":"Try two adjacent grey swatches with a checker. Save the foreground and background values, the unrounded ratio and the criterion you checked. Then increase the difference enough that the result stays clear on a small phone in bright light."}]}],"check":{"question":[{"text":"Black text at 55% opacity measures about 4.76:1 on white and 4.39:1 on a grey card. Why can the same text pass the AA ordinary-text threshold in one place and fail in the other?"}],"options":[{"text":[{"text":"The text is composited with each background, so its rendered colour and contrast change."}],"correct":true,"tempting":null},{"text":[{"text":"The browser makes the font smaller whenever the background becomes grey."}],"correct":false,"tempting":[{"text":"The example keeps the text styling fixed and changes the background only."}]},{"text":[{"text":"AA requires more contrast for text on grey backgrounds than on white."}],"correct":false,"tempting":[{"text":"The threshold is the same for ordinary text in both places."}]},{"text":[{"text":"The 0.05 term changes automatically with each page background."}],"correct":false,"tempting":[{"text":"The 0.05 term is fixed for both calculations."}]}],"order":[2,3,0,1],"why":null},"prev":{"slug":"why-hsl-lies-about-lightness","title":"The lightness slider is not lightness","minutes":9},"next":{"slug":"where-contrast-ratios-fail","title":"Where the contrast standard is wrong, and what is unsettled","minutes":9}}}