A blue status label can turn white in one browser and black in another. Both colors can pass the same WCAG threshold. A third browser may ignore the automatic choice and, without a proper fallback, inherit a dark gray that fails on the very same blue. The useful question is not just what contrast-color() picks. It is what actually gets painted in each browser you support.
What contrast-color() actually chooses
The shipped contrast-color(<color>) syntax accepts a single color and returns black or white. The CSS Color Level 5 working draft leaves the precise selection algorithm to the browser, so do not treat the CSS result as a WCAG 2 calculation. The older name color-contrast() appears in draft examples with lists of candidates. Those snippets are not a drop-in replacement for the single-argument function.
The web-platform compatibility data lists support from Chrome and Edge 147, Firefox 146 and Safari 26. It reached Baseline Newly Available in April 2026. Older browsers and embedded webviews still need a fallback; feature detection is more reliable than checking a version number in your code.
Why the two ratios can both pass AA
On the opaque blue #2277D3, white measures 4.52:1 and black measures 4.65:1 in WCAG 2. Both clear AA for normal text, but neither reaches AAA for normal text. In Chrome 158, our test picked black for that blue and for the amber below, and white for the darker cobalt. These are observations from that browser, not required outputs for all engines.
| Background | HEX | White text | Black text | Normal text contrast |
|---|---|---|---|---|
| Mid-tone blue | #2277D3 | 4.52:1 | 4.65:1 | Both AA; neither AAA |
| Terracotta | #D95D39 | 3.77:1 | 5.58:1 | Only black passes AA |
| Emerald | #10B981 | 2.54:1 | 8.28:1 | Black reaches AAA; white fails AA |
| Deep cobalt | #1D4ED8 | 6.70:1 | 3.13:1 | Only white passes AA |
| Deep emerald | #047857 | 5.48:1 | 3.83:1 | Only white passes AA |
| Amber | #FBBF24 | 1.67:1 | 12.58:1 | Black reaches AAA; white fails AA |
For a solid, opaque background with relative luminance L, the WCAG 2 ratios are (L + 0.05) / 0.05 against black and 1.05 / (L + 0.05) against white. They meet near L = 0.1791 at about 4.58:1. This is the lowest possible value of the higher ratio, not its maximum across all backgrounds. Always picking the larger WCAG 2 ratio would therefore clear 4.5:1 on a solid opaque background, but it would not guarantee 7:1. The CSS function is not a test of the final rendered pair.
Try the broken and guarded fallbacks side by side
Save this as an HTML file and open it in both a browser with support and one without it. The columns use the same three backgrounds and tested fallback text colors. The left column deliberately omits the feature query. The right asks whether the browser supports a literal contrast-color(white) before applying the declaration with var().
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compare two contrast-color() fallbacks</title>
<style>
body { background: #fff; color: #111827; font: 1rem system-ui; margin: 1rem; }
main { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }
section { padding: 1rem; border: 1px solid #d1d5db; }
h2 { margin-top: 0; font-size: 1.125rem; }
.badge {
display: inline-block;
padding: 0.375rem 0.625rem;
border-radius: 0.375rem;
background-color: var(--badge-bg);
color: var(--badge-ink);
}
.blue { --badge-bg: #2277D3; --badge-ink: #FFFFFF; }
.cobalt { --badge-bg: #1D4ED8; --badge-ink: #FFFFFF; }
.amber { --badge-bg: #FBBF24; --badge-ink: #000000; }
/* Demonstration only: this can lose the fallback. */
.broken .badge { color: contrast-color(var(--badge-bg)); }
/* Production pattern: test support without a variable. */
@supports (color: contrast-color(white)) {
.guarded .badge { color: contrast-color(var(--badge-bg)); }
}
</style>
<h1>Compare the fallback paths</h1>
<main>
<section class="broken">
<h2>Unguarded override</h2>
<p><span class="badge blue">Review</span></p>
<p><span class="badge cobalt">In progress</span></p>
<p><span class="badge amber">Pending</span></p>
</section>
<section class="guarded">
<h2>Guarded override</h2>
<p><span class="badge blue">Review</span></p>
<p><span class="badge cobalt">In progress</span></p>
<p><span class="badge amber">Pending</span></p>
</section>
</main>
</html>In Chromium 140 the unguarded column inherits the page’s dark ink #111827, which fails normal-text AA on the blue and cobalt. The guarded column keeps white on those two blues and black on amber. The reason is invalid-at-computed-value-time behavior: the var() declaration can win the cascade before the browser realizes it cannot use the result. The browser does not go back to the earlier declaration. In Chrome 158 both columns instead resolve through the supported function.
A feature query protects against missing browser support, not bad input. Give every supported badge variant a valid, tested text and background pair. If users can set arbitrary colors, validate or choose a fallback for each color instead of painting every label white. If a background is translucent, check the color it produces on the actual surface underneath.
Measure the label and the rest of the component separately
- Text: WCAG 2.2 SC 1.4.3 requires 4.5:1 for normal text and 3:1 for large text at AA. For AAA (SC 1.4.6), the thresholds are 7:1 and 4.5:1. Compare the unrounded ratio to the threshold.
- Controls and states: SC 1.4.11 calls for 3:1 against adjacent colors where the visual information is needed to identify a control or state. Testing a badge label tells you nothing about the control boundary or its focus indicator.
- Meaning: A status should still make sense without color. Use a label such as “Pending” instead of expecting users to know what amber means. See SC 1.4.1 on use of color.
Open the Contrast Checker and test both the computed foreground and your fallback against the rendered background. Analyze Your Image can help identify dominant colors in a screenshot, but sampling does not establish the source token, the focus state or conformance.
Frequently asked questions
Does contrast-color() guarantee WCAG AA?
No. The shipped function selects black or white, but the CSS specification leaves the decision algorithm to the browser. Measure the actual text and background, including any blending, and check the rest of the component separately.
Is contrast-color() the same as color-contrast()?
No. The broadly shipped contrast-color(
How do I supply a fallback for older browsers?
Set a tested foreground and background pair first. Put the contrast-color() declaration inside a feature query with a literal color argument. A function call containing var() can otherwise survive parsing but fail too late to restore the earlier declaration.