Skip to main content

Color Contrast Ratio Calculator

Calculate the contrast ratio between two colors to ensure accessibility.

Last updatedHow we build & check our tools
Results will appear here once you enter your values.

What the tool computes

Give it two colors — a background and a foreground, each by picker or as 3- or 6-digit hex — and it computes the WCAG 2.x contrast ratio: the relative luminance of the lighter color plus 0.05, divided by the same for the darker one. The scale runs from 1:1 (identical colors) to 21:1 (black on white), shown to two decimals.

The same number is judged against four thresholds at once, each with a Pass or Fail badge: 4.5:1 for AA normal text, 3:1 for AA large text, 7:1 for AAA normal text and 4.5:1 for AAA large text. A live preview renders your foreground as sample text and as an inverted button label on the background, so you see both the pair and the number behind the verdicts.

When to reach for it

The tool answers one question fast: does this foreground color work on this background? Paste the two hex values from your stylesheet or theme file while you code, review a pull request, or sanity-check a designer's handoff — the ratio and verdicts update as you type.

It suits any foreground, not just text: the same 3:1 threshold governs icons, input borders and focus indicators under WCAG 1.411 non-text contrast, so the verdicts read the same for a border as for a heading. Work state by state: check the resting pair, then hover, focus and the dark-theme variant, because each combination is a separate pair. If a pair sits just under a threshold, adjust lightness first — a small lightness shift moves the ratio far more than a hue change, since the calculation is driven by brightness.

Limits to keep in mind

Input is hex only — 3 or 6 digits, with or without the leading hash. rgb(), hsl(), color names and alpha channels are not parsed, so flatten any translucent color against what actually sits behind it before entering it. The preview shows sample text, not your real typeface, so you decide which threshold applies: large text means at least 24px, or at least 18.66px bold — anything smaller is normal text and needs 4.5:1.

Text over images or gradients must be tested against the worst-case pixel behind the glyphs, and exempt content — logos, decorative elements, disabled controls — can look like a failure when it is not. The WCAG 2.x ratio is also a known-imperfect model, especially for light text on dark backgrounds; it remains, however, the number auditors and scan tools test against.

Frequently Asked Questions

Common questions about the Color Contrast Ratio Calculator

Not for the score. The ratio divides the lighter luminance by the darker one, so background and foreground can be swapped without changing the number. The fields matter for the live preview, which renders the foreground color as text and as a button label on the background.

From the same team

Turn your GPU into an OpenAI-compatible API endpoint

Wide Area AI routes your LLM API calls to your own hardware over a Cloudflare Tunnel — free local inference with edge caching and automatic cloud failover. Works with any OpenAI SDK.

Start routing — free

Sources & References

Contrast (Minimum) 1.4.3

Defines the 4.5:1 and 3:1 minimum contrast ratios for text that this calculator reports against.

WCAG 2.2 Recommendation

Full WCAG 2.2 text, including the relative luminance formula used to compute the ratio.