function

contrast-color() — CSS reference

Choose a black or white foreground intended to contrast with the input color. The function is not a general WCAG conformance checker: background compositing, surrounding colors and text size still matter. Use a deliberately chosen fallback first and verify the actual foreground/background combination. The local tested browser does not implement this syntax.

Formal Syntax & Structure

css syntaxcss
contrast-color(<color>) (Level 5 draft)

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS color lab</title><style>body {margin:0} .sample {height:12px;background:#006050}p {padding:12px;background:white;color:black;border:2px solid currentColor} #a{background:black;color:white;color:contrast-color(black)} #b{background:white;color:black;color:contrast-color(white)}
</style><body><p id="a">First color sample</p><p id="b">Second color sample</p></body></html>
CSS Reference