CSS Colors & StylingBy PaletteKey Team 7 min read

How to Use OKLCH in CSS

Practical guide to implementation, custom properties, theme tokens, and fallbacks.

Key Technical Takeaway

OKLCH is natively supported in all modern browsers via the oklch(L C H [/ A]) CSS function. Learn how to write OKLCH rules, structure CSS custom properties, construct hover states, and handle progressive enhancements.

The CSS oklch() Function Syntax

The CSS oklch() function accepts three positional arguments plus an optional alpha parameter: Lightness (L), Chroma (C), and Hue angle (H).

/* Basic Syntax */
element {
  color: oklch(L C H [/ A]);
}

/* Practical Examples */
.primary-btn {
  /* L: 0.62 (62% lightness)
     C: 0.22 (Chroma intensity)
     H: 250 (Blue-violet hue angle)
     A: 0.95 (95% opacity) */
  background-color: oklch(0.62 0.22 250 / 0.95);
}

.subtle-badge {
  background-color: oklch(0.95 0.04 140); /* Soft mint background */
  color: oklch(0.35 0.12 140);            /* High-contrast mint text */
}

Structuring Design Tokens with CSS Custom Properties

By breaking OKLCH into individual CSS custom properties for Lightness, Chroma, and Hue, you can programmatically derive hover states, active states, and dark mode variants without re-declaring hex codes.

:root {
  /* Base Brand Hue & Chroma */
  --brand-h: 252;
  --brand-c: 0.24;

  /* Lightness Scale Tokens */
  --brand-50:  oklch(0.97 calc(var(--brand-c) * 0.2) var(--brand-h));
  --brand-500: oklch(0.60 var(--brand-c) var(--brand-h));
  --brand-700: oklch(0.45 var(--brand-c) var(--brand-h));
}

.btn-brand {
  background-color: var(--brand-500);
  color: white;
  transition: background-color 0.15s ease;
}

/* Interactive Hover State: Darken L by 0.08 while preserving Hue & Chroma */
.btn-brand:hover {
  background-color: oklch(0.52 var(--brand-c) var(--brand-h));
}

Modern CSS Gradients with OKLCH Space

Standard CSS gradients interpolate in sRGB space, frequently creating dirty, desaturated grey midpoints. By explicitly specifying `in oklch` in `linear-gradient()`, browsers interpolate smoothly along perceptual lightness and hue paths.

/* Legacy sRGB Gradient (Can produce muddy grey middle) */
.legacy-gradient {
  background: linear-gradient(to right, blue, yellow);
}

/* Modern OKLCH Gradient (Vibrant, perceptually uniform transition) */
.oklch-gradient {
  background: linear-gradient(in oklch to right, oklch(0.6 0.25 250), oklch(0.85 0.20 90));
}

Browser Compatibility and Fallbacks

OKLCH is supported across all major browser engines (Chrome 111+, Safari 15.4+, Firefox 113+, Edge 111+). For maximum durability in older legacy environments, use `@supports` or fallback declarations:

.card {
  /* Fallback for legacy browser engines */
  background-color: #2563eb;
  
  /* Modern browsers override with wide-gamut OKLCH */
  background-color: oklch(0.58 0.23 254);
}

@supports not (color: oklch(0.5 0.1 0)) {
  .card {
    background-color: #2563eb;
  }
}

Put Theory into Practice with Free Color Tools

Apply the concepts from this guide directly in your web workflow with our interactive tools.