CSS contrast-color() picks white or black text for any background
The contrast-color() function in CSS Color Level 5 takes a background color and returns white or black, whichever has higher contrast. It has shipped in Chrome 147, Firefox 146 and Safari 26 since April 2026. On mid-tone backgrounds the best result bottoms out near 4.58:1.
- The function takes one color and returns white or black by maximum contrast
- Support: Chrome 147, Firefox 146, Safari 26, Baseline since April 10, 2026
- The better of the two options never drops below √21 ≈ 4.58:1 under WCAG
- Older browsers need @supports; a var()-based fallback does not work
Read next
Software