On this page
  1. Color & Value Functions
  2. Contents
  3. var() with Fallbacks
  4. Modern Color Spaces (oklch(), color-mix(), light-dark())

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())

: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

Related notes