Fundamentals OKLCHColor TheoryCSSBasics

What is OKLCH? Understanding Modern Color Spaces

Discover OKLCH, a perceptually uniform color space that revolutionizes how we work with colors in CSS. Learn why it's superior to RGB and HSL for creating accessible, beautiful designs.

What is OKLCH? Understanding Modern Color Spaces

OKLCH is a revolutionary color space that's changing how we think about and work with colors in web design. Unlike traditional color models like RGB or HSL, OKLCH provides perceptually uniform colors, meaning that a change in the numerical value creates a proportional change in how humans perceive the color.

Understanding the Components

OKLCH stands for three components:

L - Lightness (0% to 100%)

The lightness value represents how light or dark a color appears. Unlike HSL's lightness, OKLCH lightness is perceptually uniform, meaning:

  • oklch(50% ...) will look equally bright regardless of hue
  • In HSL, hsl(240deg 100% 50%) (blue) appears darker than hsl(60deg 100% 50%) (yellow)
  • OKLCH fixes this by using human perception as the foundation
/* These all have the same perceived brightness */
.color-red { color: oklch(0.50 0.20 30); }
.color-green { color: oklch(0.50 0.20 140); }
.color-blue { color: oklch(0.50 0.20 250); }

C - Chroma (0 to ~0.4)

Chroma represents the "colorfulness" or saturation of a color:

  • 0 = grayscale (no color)
  • Higher values = more vivid colors
  • Maximum chroma depends on the lightness and hue
  • Unlike HSL saturation, chroma maintains consistent vibrancy across different lightnesses
/* Increasing chroma from gray to vibrant */
.gray { color: oklch(0.70 0.00 250); }
.muted { color: oklch(0.70 0.10 250); }
.vibrant { color: oklch(0.70 0.25 250); }

H - Hue (0 to 360 degrees)

Hue represents the color angle on the color wheel, similar to HSL:

  • / 360° = Red
  • 120° = Green
  • 240° = Blue
  • Works the same way as HSL hue
/* Rainbow using consistent lightness and chroma */
.red { color: oklch(0.65 0.22 30); }
.yellow { color: oklch(0.65 0.22 90); }
.green { color: oklch(0.65 0.22 140); }
.cyan { color: oklch(0.65 0.22 200); }
.blue { color: oklch(0.65 0.22 250); }
.magenta { color: oklch(0.65 0.22 320); }

Why OKLCH Matters

1. Perceptual Uniformity

The biggest advantage of OKLCH is perceptual uniformity. When you create a color palette by adjusting only the lightness value, all colors will have the same perceived brightness:

/* Perfect shade palette */
.shade-100 { background: oklch(0.95 0.15 250); }
.shade-200 { background: oklch(0.85 0.15 250); }
.shade-300 { background: oklch(0.75 0.15 250); }
.shade-400 { background: oklch(0.65 0.15 250); }
.shade-500 { background: oklch(0.55 0.15 250); }
.shade-600 { background: oklch(0.45 0.15 250); }

2. Better Accessibility

Because OKLCH lightness values match human perception, it's much easier to ensure proper contrast ratios for accessibility:

/* Dark text on light background - guaranteed contrast */
.container {
  background: oklch(0.95 0.05 250); /* Light background */
  color: oklch(0.30 0.10 250);      /* Dark text */
  /* Adequate contrast because lightness values are far apart */
}

3. Wider Color Gamut Support

OKLCH can represent colors beyond the sRGB gamut, including Display P3 colors for modern displays:

/* Vibrant P3 color that sRGB can't represent */
.neon-blue {
  color: oklch(0.65 0.30 250);
  /* Will fallback gracefully on older displays */
}

4. Predictable Color Manipulation

Creating tints, shades, and tones is straightforward and predictable:

/* Base color */
--base: oklch(0.60 0.20 250);

/* Lighter version: increase lightness */
--light: oklch(0.80 0.20 250);

/* Darker version: decrease lightness */
--dark: oklch(0.40 0.20 250);

/* More saturated: increase chroma */
--vibrant: oklch(0.60 0.28 250);

/* Less saturated: decrease chroma */
--muted: oklch(0.60 0.12 250);

Browser Support

OKLCH is part of the CSS Color Module Level 4 spec and has excellent modern browser support:

  • ✅ Chrome 111+ (March 2023)
  • ✅ Safari 15.4+ (March 2022)
  • ✅ Firefox 113+ (May 2023)
  • ✅ Edge 111+ (March 2023)

For older browsers, you can provide fallbacks:

.element {
  /* Fallback for older browsers */
  color: #4080ff;
  
  /* Modern browsers */
  color: oklch(0.60 0.18 250);
}

When to Use OKLCH

OKLCH is ideal for:

Design systems - Consistent shade palettes across all colors
Accessibility - Easier to meet WCAG contrast requirements
Dark mode - Predictable color conversions between themes
Animations - Smooth, perceptually uniform color transitions
Modern displays - Access to wider color gamuts like P3

Getting Started

The easiest way to start using OKLCH is with the oklch() function in CSS:

:root {
  /* Primary color palette */
  --primary-light: oklch(0.75 0.18 250);
  --primary: oklch(0.60 0.18 250);
  --primary-dark: oklch(0.45 0.18 250);
  
  /* Semantic colors */
  --success: oklch(0.65 0.18 140);
  --warning: oklch(0.70 0.20 85);
  --error: oklch(0.55 0.22 30);
  
  /* Neutral palette */
  --gray-50: oklch(0.97 0.02 270);
  --gray-100: oklch(0.93 0.02 270);
  --gray-200: oklch(0.85 0.03 270);
  --gray-300: oklch(0.75 0.03 270);
  --gray-400: oklch(0.65 0.03 270);
  --gray-500: oklch(0.55 0.04 270);
  --gray-600: oklch(0.45 0.04 270);
  --gray-700: oklch(0.35 0.04 270);
  --gray-800: oklch(0.25 0.03 270);
  --gray-900: oklch(0.15 0.02 270);
}

Conclusion

OKLCH represents a major step forward in how we work with color on the web. Its perceptual uniformity, accessibility benefits, and support for wide color gamuts make it the ideal choice for modern web design. Whether you're building a design system, ensuring accessibility compliance, or just want more predictable and beautiful colors, OKLCH is the color space you should be using.

Ready to dive deeper? Check out our OKLCH vs HSL comparison or learn about Display P3 colors.