UtilityPilot.Find a tool

Web & Publishing · PRACTICAL GUIDE

How text color contrast is calculated

Calculate sRGB luminance and understand text contrast thresholds without mistaking them for a full accessibility audit.

Use the actual foreground and background

A color pair must represent the rendered text and what is immediately behind it. If an image or gradient is involved, a single chosen background value may not describe every part of the text. Sample an image pixel where appropriate, but do not assume one pixel proves the whole design works.

The checker requires opaque colors. Composite transparent layers against their real background before evaluating them.

Linearize before measuring luminance

Normalize each sRGB channel to 0–1. For a channel c at or below 0.04045, use c / 12.92. Otherwise use ((c + 0.055) / 1.055)2.4. Relative luminance is 0.2126R + 0.7152G + 0.0722B using those linearized channels.

The contrast ratio is (lighter luminance + 0.05) / (darker luminance + 0.05). Black and white produce 21:1; equal colors produce 1:1.

Read the correct threshold

AA normal text requires 4.5:1 and AA large text 3:1. AAA normal text requires 7:1 and AAA large text 4.5:1. Large text means at least 18 points regular or 14 points bold—24 CSS pixels or approximately 18.67 CSS pixels bold.

Do not round before evaluating a threshold. A ratio of 4.499 can display as 4.50 but still fail the 4.5 requirement. The tool uses the unrounded calculation for its result.

Apply the result in context

Check the real font size and weight, then inspect keyboard focus, errors and non-text controls separately. Passing a text color pair does not certify page accessibility, typography or readability.

Use the W3C contrast explanation for the criterion and exceptions. Use Color converter when your editor requires a different notation; all these conversions remain in sRGB rather than a print CMYK workflow.

When a passing pair is not enough

Do not stop at one passing pair when text sits on a gradient, photograph or varying background—sample multiple points or redesign the treatment. Do not use a passing pair to justify disabled-control colors that also need to meet non-text contrast. Do not forget hover, focus and error states; each rendered combination needs its own check.

Also skip “we passed AA” as a whole-page claim. Keyboard access, labels, zoom, reflow and motion preferences are separate criteria. The checker is one instrument, not an audit.

Rounding and threshold traps

Display rounds to two decimals; Pass/Fail uses the unrounded value. A displayed 4.50 can fail AA normal text. Large-text thresholds depend on actual CSS pixel size and weight—“looks big” is not a measurement. Bold is not the same as a heavier font family that the browser does not treat as bold.

When documenting a result, record the unrounded ratio (or at least four decimals), the size and weight used, and the criterion (AA/AAA, normal/large). Without those four facts the pass cannot be reproduced.

Applying the result in a design system

Store foreground, background, ratio, size, weight and criterion together as a token pair—not only the two hex values. Re-check when either colour changes, when the font size changes, or when the background becomes an image. For dark mode, re-run the pair; inverting hex values does not preserve WCAG ratios.

Feed sampled image colours through the converter first to get opaque HEX, then check. For documentation, link the criterion explanation (W3C contrast guidance) alongside your recorded ratio so reviewers see the standard you targeted.

Put it into practice

Choose the tool that matches your next step. Keep an original copy and inspect the result before using it elsewhere.

Color Contrast CheckerCheck a foreground/background text pair.Web & PublishingHEX RGB HSL converterTranslate a design color into another notation.Web & PublishingImage color pickerSample usable colors from artwork.Images