Loading...
.badge {
background: var(--bg);
color: contrast-color(var(--bg));
}.badge {
background: var(--bg);
color: white;
}
@supports (color: contrast-color(red)) {
.badge {
color: contrast-color(var(--bg));
}
}With var() an unsupported value fails only at computed time, so @supports guards the contrast-color() line.
contrast-color() sits inside @supports (color: contrast-color(red)), because a plain fallback line does not help when the value uses var().contrast-color(), not by a JavaScript luminance function.No. It picks whichever of black or white contrasts more, but on mid-tone backgrounds even the better one may not reach the contrast you need.
Yes, like contrast-color(var(--bg)). Use the same property for the background so the pair always matches.