HomeDeveloper & IT › Colour Contrast Checker

Colour Contrast Checker

Computes the WCAG 2.1 contrast ratio between a foreground and a background colour from their relative luminance (sRGB linearised) and checks it against the AA and AAA thresholds for normal text, large text and non-text UI components.

When to use

You are choosing text or button colours for a website or app and need to verify accessibility compliance (WCAG 1.4.3, 1.4.6, 1.4.11).

Do not use when: Colours have transparency (composite them onto the background first), you need perceptual difference (ΔE) or colour-space conversion (use color-converter).

Formula

For each channel c = value/255: c_lin = c/12.92 if c ≤ 0.03928 else ((c + 0.055)/1.055)^2.4; L = 0.2126·R_lin + 0.7152·G_lin + 0.0722·B_lin; contrast = (L1 + 0.05) / (L2 + 0.05) with L1 ≥ L2

WCAG 2.1 definitions of relative luminance and contrast ratio for sRGB colours; thresholds 4.5:1 / 3:1 (AA), 7:1 / 4.5:1 (AAA) and 3:1 for non-text elements. The ratio is not rounded before comparison, so 4.48:1 fails AA normal text.

Inputs

ParameterTypeUnitRequiredDescription
foregroundstringyesHex colour: #RRGGBB or #RGB shorthand, with or without the #.
backgroundstringyesHex colour: #RRGGBB or #RGB shorthand, with or without the #.

Outputs

OutputTypeUnitDescription
contrast_rationumber(L_lighter + 0.05) / (L_darker + 0.05), from 1 (identical) to 21 (black on white).
contrast_ratio_textstringThe ratio written as n:1.
luminance_foregroundnumberWCAG relative luminance of the foreground, 0 (black) to 1 (white).
luminance_backgroundnumberWCAG relative luminance of the background.
aa_normal_textbooleanPasses SC 1.4.3 for text below 18 pt (24 px) regular or 14 pt (18.66 px) bold.
aa_large_textbooleanPasses SC 1.4.3 for large text.
aaa_normal_textbooleanPasses SC 1.4.6 enhanced contrast for normal text.
aaa_large_textbooleanPasses SC 1.4.6 for large text.
ui_componentsbooleanPasses SC 1.4.11 non-text contrast for icons, borders and focus indicators.
ratingstringSummary of the highest level passed.
foreground_normalizedstringForeground as #RRGGBB.
background_normalizedstringBackground as #RRGGBB.

Example

Black on white: {"foreground":"#000000","background":"#ffffff"}{"contrast_ratio":21,"luminance_foreground":0,"luminance_background":1,"aa_normal_text":true,"aaa_normal_text":true,"ui_components":true,"contrast_ratio_text":"21:1"}

#777777 on white: {"foreground":"777777","background":"fff"}{"contrast_ratio":4.48,"luminance_foreground":0.1845,"aa_normal_text":false,"aa_large_text":true,"aaa_normal_text":false,"aaa_large_text":false,"ui_components":true,"foreground_normalized":"#777777","background_normalized":"#FFFFFF"}

GET https://tttkmbb.com/api/v1/calculate/color-contrast?foreground=%23000000&background=%23ffffff

Machine access

Sources

FAQ

What counts as large text?

At least 18 pt (24 px) regular or 14 pt (about 18.66 px) bold; large text only needs 3:1 for AA and 4.5:1 for AAA.

Does swapping foreground and background change the ratio?

No, the formula always divides the lighter luminance by the darker one, so the ratio is symmetric.

Why does #777777 fail even though it looks readable?

Its ratio on white is 4.48:1, just under the 4.5:1 AA threshold; #767676 (4.54:1) is the lightest grey that passes.

Related calculators