Primary references
These sources support the standards and technical explanations in this guide. Color Pick recommendations and product-specific limitations are identified separately in the article.
Build dynamic CSS color relationships with relative color syntax, light-dark(), and contrast-color() while keeping deterministic fallbacks and honest support boundaries.
Use relative color syntax when a state should remain mathematically tied to a source color. Use light-dark() for values selected by the active color scheme after opting into color-scheme. Use contrast-color() as a black-or-white helper, not a substitute for a full contrast audit. Declare measured fallbacks first and isolate each feature with @supports.
A relative color can reuse and calculate channels from an origin color.
:root {
--brand: #2563eb;
--brand-hover: #1d4ed8;
}
@supports (color: oklch(from red l c h)) {
:root {
--brand-hover: oklch(from var(--brand) calc(l - .07) c h);
}
}light-dark() reacts to the used color scheme.
:root {
color-scheme: light dark;
--surface: #ffffff;
}
@supports (color: light-dark(white, black)) {
:root {
--surface: light-dark(#ffffff, #0f172a);
}
}The function returns black or white, but a mid-tone background can still be problematic.
Calculate a black-or-white fallback.
Record the actual contrast ratio.
Use contrast-color() only after the fallback declaration.
Change the background when neither black nor white meets the intended requirement.
Retest small text, large text, icons, and focus indicators separately.
Support can differ between modern functions.
A generated palette is not the final rendered experience for every user.
CSS Color 5 is still evolving.
Generate fallbacks and @supports-gated modern CSS.
Yes. The origin color can be var(--token), provided the resolved value is a valid color.
It can simplify individual color values, but media queries remain useful for non-color layout, images, and broader theme behavior.
Do not assume it. It returns black or white and may not solve every mid-tone background or product-specific requirement. Measure the result.
These sources support the standards and technical explanations in this guide. Color Pick recommendations and product-specific limitations are identified separately in the article.