On this page
Color & Value Functions
Prev: Math & Sizing Functions | Up: functions | Next: at_rules
Rel: Typography & Color, Responsive Design & Theming
Ref: MDN Web Docs — CSS Color Values
Tags: #public #web #css #functions #color
Contents
var() with Fallbacks
var(--token, fallback) resolves a custom property or falls back to the second argument (which may itself be another var()):
.badge {
background: var(--badge-bg, var(--surface-alt, #eee));
}
Modern Color Spaces (oklch(), color-mix(), light-dark())
oklch(L C H / alpha): Perceptually uniform lightness, chroma, and hue — shifting hue keeps perceived brightness consistent.color-mix(in oklch, color1 p1, color2): Derives hover/border tints dynamically from a single brand token.light-dark(lightColor, darkColor): Switches values automatically based on the activecolor-scheme.
:root {
color-scheme: light dark;
--brand: oklch(58% 0.18 250);
--brand-hover: color-mix(in oklch, var(--brand) 85%, black);
--bg: light-dark(#ffffff, #141619);
--fg: light-dark(#1a1d21, #eceff4);
}
Linked from
- tuts/css/functions
- tuts/css/functions/color
- tuts/css/functions/color/color-mix
- tuts/css/functions/color/light-dark
- tuts/css/functions/color/linear-gradient
- tuts/css/functions/color/oklch
- tuts/css/functions/color/var
- tuts/css/functions/color_and_value_functions
- tuts/css/functions/math_and_sizing_functions
- tuts/css/properties/typography_and_color
- tuts/css/tutorials/responsive_design_and_theming
Related notes
- tuts/css/functions Linked here; links to this page; shared tags: #css, #functions, #web
- tuts/css/functions/math_and_sizing_functions Linked here; links to this page; shared tags: #css, #functions, #web
- tuts/css/properties/typography_and_color Linked here; links to this page; shared tags: #color, #css, #web
- tuts/css/tutorials/responsive_design_and_theming Linked here; links to this page; shared tags: #css, #web
- tuts/css/functions/color links to this page; shared tags: #color, #css, #functions, #web
- tuts/css/functions/color/color-mix links to this page; shared tags: #color, #css, #functions, #web
- tuts/css/functions/color/light-dark links to this page; shared tags: #color, #css, #functions, #web
- tuts/css/functions/color/linear-gradient links to this page; shared tags: #color, #css, #functions, #web
- tuts/css/functions/color/oklch links to this page; shared tags: #color, #css, #functions, #web
- tuts/css/functions/color/var links to this page; shared tags: #color, #css, #functions, #web