Contrast-color() - Function CSS
Summary of characteristics of the contrast-color() function
autoDiscrète: during an animation, the contrast-color() property passes from one value to another without transition.Single: single value (no order).Syntax diagram of contrast-color().
contrast-color() function.Click on the terms of the diagram for more precision.
On the diagram, the terms in bold are the predefined terms in CSS, the others are described below:
coloris a color, expressed in any format recognized by CSS (see Colors).
Description of the contrast-color() function.
When colors are created dynamically, it can sometimes be tricky to find a text color that contrasts enough with the background. The function
contrast-color() determines a color with sufficient contrast to be displayed over a background of the specified color. The returned color can be
either white or black.
Of course, if the background is not solid (an image, for example), the contrast-color() function cannot be effective.
⚠ This feature is still poorly supported by browsers. If you use a compatible browser (like ), the text below will be displayed in white. Otherwise, you won't see the text at all.
The contrast-color() value can be used with the following properties:
Primarily used with the color property, the contrast-color() function can also be suitable for any properties that expect a color.
Syntaxes of the contrast-color() function.
- <property>: color-contrast(#ff8045); color
coloris a color expressed in any syntax recognized by CSS (see Colors). The function returnswhiteorblackdepending on which color has the best contrast characteristics with thecolor.
Animation with the contrast-color() function.
The animation is done based on the background color, between white and black. The text color, however, is set to contrast-color().
On compatible browsers, you should always be able to read the text, in black on a white background or white on a black background.
L'
Simulator.
The simulator allows you to change the background color of the block below. The text color, however, is set by contrast-color().
Note: the simulator sets a variable (custom property) named --demo1, which is then used to determine the background color
and is passed as a parameter to the function contrast-color() to determine the foreground color.
Browsers compatibility with contrast-color() function.
The function contrast-color() is still very poorly supported by browsers (2025). It is still too early to use it.
contrast-color() function, which determines the color (between white and black) that has the highest contrast with a given color.cntrast-color()function
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Safari

Samsung Internet

Safari sur IOS

Androïd Brower

Chrome

Chrome pour Androïd

Edge

Firefox

Firefox pour Androïd

KaiOS Browser

Opéra

Opéra mini
Historic of the contrast-color() function.
-
CSS Color Module Level 5
Introduction of thecontrast-color()function to determine a foreground color based on the background color.March 03, 2020Working Draft.
See also, regarding colors.
Below is the list of properties, functions, and other terms related to color management in CSS.
Properties:
currentcolor.Functions:
sRGB, sRGB-linear, profoto, etc).



L*a*b* system.L*C*H* system.L*a*b* system with a perceptual correction.L*C*H* system with a perceptual correction
At-rules:

color() function.Descriptors :

@color-profile at-rule.
@color-profile directive. Defines the method for converting from one color profile to another.


