WCAG colour contrast explained
How the WCAG contrast ratio is calculated, which ratios you need for text and UI, and worked examples with real colours.
By the tools4free.dev team · Last reviewed 4 December 2026
WCAG colour contrast is a measured ratio between the lightness of text and its background. To meet Level AA, normal-size text needs a ratio of at least 4.5:1, large text needs at least 3:1, and meaningful interface parts such as input borders and icons need at least 3:1 against what sits next to them. This guide shows how the ratio is calculated, how to check real colours, and where designers most often fall short.
What the ratio actually measures
The ratio compares the relative luminance of two colours. Relative luminance is a number from 0 (pure black) to 1 (pure white) that approximates how bright a colour looks to a person. The ratio is then:
contrast = (L1 + 0.05) / (L2 + 0.05)
L1 is the luminance of the lighter colour and L2 the luminance of the darker one. The 0.05 term stops the ratio from becoming infinite when one colour is black. The result runs from 1:1 (identical colours) to 21:1 (black on white).
Calculating relative luminance
Each sRGB channel (red, green, blue) is first divided by 255 to give a value between 0 and 1. Each value is then linearised, because screens do not respond to channel values in a straight line:
if c <= 0.03928: c_lin = c / 12.92
else: c_lin = ((c + 0.055) / 1.055) ^ 2.4
L = 0.2126 * R_lin + 0.7152 * G_lin + 0.0722 * B_lin
The weights show why green looks bright and blue looks dark: the eye is far more sensitive to green. WCAG 2.2 defines this formula in its definition of "relative luminance". Some tools use 0.04045 as the cut-off, taken from the sRGB standard itself. The two thresholds give the same results to well within rounding for real colours, so you will not see a pass turn into a fail because of it.
The thresholds you need to remember
| What you are checking | Level AA | Level AAA | WCAG criterion |
|---|---|---|---|
| Normal text | 4.5:1 | 7:1 | 1.4.3 and 1.4.6 |
| Large text | 3:1 | 4.5:1 | 1.4.3 and 1.4.6 |
| Icons, input borders, focus rings, chart lines | 3:1 | no AAA rule | 1.4.11 Non-text Contrast |
| Logos and purely decorative items | exempt | exempt | 1.4.3 and 1.4.11 |
| Disabled controls | exempt | exempt | 1.4.3 and 1.4.11 |
"Large text" means at least 18 point (24 CSS pixels) or at least 14 point bold (about 18.66 CSS pixels). Anything smaller is normal text. Ratios are not rounded up: 4.49:1 fails a 4.5:1 requirement.
Worked example 1: grey text on white
Light grey text is the most common contrast failure, so test the border cases. Take white (#ffffff, luminance 1.0) and two greys that look almost identical.
- #767676 on white. Each channel is 118/255 = 0.4627. Linearised, that is ((0.4627 + 0.055) / 1.055) ^ 2.4 = 0.1812. All three channels match, so L = 0.1812. Ratio = (1.0 + 0.05) / (0.1812 + 0.05) = 4.54:1. This passes AA for normal text.
- #777777 on white. One step lighter. L = 0.1845, so the ratio is 1.05 / 0.2345 = 4.48:1. This fails AA for normal text by a hair, although you cannot see the difference.
#767676 is the famous "lightest grey that passes on white" for body text. For a safer margin, #595959 on white gives 7.00:1, which also meets AAA.
Worked example 2: a brand blue and a button
Suppose a brand colour is #1a73e8 and the design calls for white button labels on it. Computed as above, white on #1a73e8 is 4.51:1. That passes AA, but with almost no room, and a slightly lighter shade would fail. Darkening to #0b57d0 raises the ratio to 6.39:1, which is comfortable.
Now try a red error colour. White on #e53935 is 4.23:1, which fails for normal text. White on #c62828 is 5.62:1 and passes. A small darkening of the same hue usually fixes a failing colour without changing the feel of the design.
Contrast is symmetrical, so these numbers also tell you how the colours behave in reverse. #1a73e8 text on a white page is 4.51:1 as well.
Worked example 3: a UI border
An input field with a border of #949494 on a white page has a ratio of 3.03:1. That passes the 3:1 rule for non-text contrast, so the field's boundary is perceivable. A border of #b3b3b3 would be about 2.1:1 and would fail, even though it looks tidy and modern. If the field has a visible filled background that already contrasts with the page, the border itself may not be required; the rule is that the control must be identifiable.
Where the contrast rules apply
Text over images and gradients
WCAG does not allow you to measure only the best spot. Test the text against the part of the background where it is hardest to read. A common fix is a semi-opaque panel behind the text, or a dark overlay on the image. Check the final blended colour, not the colour you typed before opacity was applied.
States and focus
Hover, focus, active and selected states are included. A focus ring that is a thin pale outline can fail 3:1 against the page. WCAG 2.2 also adds Focus Appearance (2.4.13, Level AAA), which sets size and contrast expectations for the focus indicator, so a visible, high-contrast ring is worth the effort.
Placeholders and hints
Placeholder text is still text. A light grey placeholder that fails 4.5:1 is a failure, and it is a frequent one because designers treat it as secondary.
Dark mode
Dark themes need their own check. Mid-grey text on near-black can fail, and pure white on pure black can be harsh enough that some readers prefer a slightly softer pair. Check each theme separately rather than assuming the inverse works.
Common mistakes
- Judging by eye on a bright, high-quality monitor. Phones in sunlight and older screens reduce contrast; the ratio gives you headroom.
- Rounding 4.48 up to "about 4.5". The rule is a hard threshold.
- Checking text but not icons, chart series, borders or focus rings.
- Using colour alone to carry meaning, such as red for errors with no icon or text. This is a separate rule (1.4.1 Use of Colour), but it often comes up in the same review.
- Forgetting opacity. Text at 60% opacity on white is a different, lighter colour than the one in your palette.
- Treating a large heading as an excuse for small grey captions. The 3:1 allowance covers only large text.
- Relying on a brand colour as it is. Brand palettes are often chosen for print, and a darker "text" variant for the web is normal practice.
A practical workflow
- Define your palette as named tokens (for example
--text,--text-muted,--link,--border). - For each token, check it against every surface it appears on, in both light and dark themes.
- Record the ratio next to the token, so later edits are checked against a number rather than memory.
- Re-check after any opacity, overlay or gradient is added.
Frequently asked questions
Is 4.5:1 required by law?
It depends on where you are. Many accessibility laws and procurement rules point to WCAG 2.x Level AA, which includes the 4.5:1 rule, but the exact legal wording differs by country and sector. Treat AA as the practical target and check the rules that apply to you.
Does the ratio change for dark text on a light background versus the reverse?
No. The formula divides the lighter luminance by the darker one, so the order does not matter. Readability can still feel different in practice, which is why dark mode deserves its own review.
Will WCAG 3 replace this ratio?
WCAG 3 is a working draft that explores a different contrast method that takes font size and weight into account. It is not a finished standard, so WCAG 2.2 and its ratios remain the reference to test against.
Does a logo have to meet the ratio?
No. Logos and brand names are exempt from the text contrast requirement, although a readable logo is good practice.