Learn

How WCAG contrast is calculated

The formula behind the 4.5:1 and 3:1 checks.

WCAG 2 measures the contrast between two colours as a ratio of their relative luminance. The ratio runs from 1:1, two identical colours, to 21:1, black on white.

Relative luminance starts from the sRGB channel values, each scaled to the range 0 to 1. Each channel c is linearised: c / 12.92 when c is 0.04045 or less, otherwise ((c + 0.055) / 1.055) to the power 2.4. The three are then weighted, L = 0.2126 R + 0.7152 G + 0.0722 B, because the eye is most sensitive to green light and least to blue.

The contrast ratio is (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter colour. The 0.05 on each side keeps the ratio finite when one colour is black. Mid grey #777777 on white gives about 4.48, just under the 4.5:1 that level AA asks for normal text.

The levels are 4.5:1 for normal text and 3:1 for large text at AA, 7:1 and 4.5:1 at AAA, and 3:1 for user-interface parts and graphics. Large text means 18 point, or 14 point bold. Avoid checking a colour pair only once. Try every pair you use in the Colour Contrast Checker.

Open Colour Contrast Checker (WCAG)

By Rahul Kaushl (OccultMaster) · Instagram · YouTube · Facebook