contrast-color()

Experimental

A function that automatically selects a text color with the best contrast against a given background color. It's a game-changer for dynamic themes, ensuring text remains readable regardless of the background.

Quick example

.dynamic-badge {
  background-color: var(--bg-variable);
  /* Color is automatically chosen for best contrast */
  color: contrast-color(var(--bg-variable));
}

contrast-color() Browser Support

Limited availability 0% global usage

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Not ready for production without a fallback.

Interop 2026 focus area ? Learn more →
ESC