Color Spaces
Overview
Section titled “Overview”The <color-input> component supports multiple color spaces for editing colors:
- OKLCH, OKLAB - Perceptually uniform (recommended)
- HSL, HWB - Intuitive but not perceptually uniform
- LAB, LCH - CIE perceptual spaces
- sRGB - Standard web RGB
- Display P3, Rec2020 - Wide-gamut RGB
- Other: a98-rgb, prophoto, xyz variants
OKLCH (Recommended)
Section titled “OKLCH (Recommended)”OKLCH is the recommended choice for most design work. It’s a perceptually uniform color space designed to match human vision.
- Value
- oklch(70% 0.2 240)
- Color Space
- oklch
- Gamut
- —
- Contrast Color
-
—
View Code
<color-input value="oklch(70% 0.2 240)" colorspace="oklch" theme="auto"></color-input>Why OKLCH?
Section titled “Why OKLCH?”- Perceptually uniform - Equal numeric changes produce equal visual changes
- Predictable lightness - Adjusting L keeps perceived brightness constant
- Consistent chroma - Saturation behaves intuitively across all hues
- Wide gamut support - Works with Display P3, Rec2020, and beyond
- Better than HSL - No hue shifting or unexpected brightness changes
Channels
Section titled “Channels”- L (Lightness): 0–100% - Perceived brightness
- C (Chroma): 0–100% (0–0.4 in decimal) - Colorfulness/saturation
- H (Hue): 0–360° - Color angle (0=red, 120=green, 240=blue)
Syntax
Section titled “Syntax”oklch(70% 0.2 240) /* Vibrant blue */oklch(85% 0.15 120) /* Light green */oklch(50% 0.25 30) /* Rich orange */oklch(90% 0.05 180 / 0.8) /* Subtle cyan with alpha */Best Practices
Section titled “Best Practices”Color Scales:
/* Keep C and H constant, vary L for consistent hue */--brand-50: oklch(95% 0.1 240);--brand-500: oklch(70% 0.2 240);--brand-900: oklch(30% 0.15 240);Accessible Contrast:
/* Lighter colors need less chroma for clarity */--text-light: oklch(95% 0.02 240);--text-dark: oklch(25% 0.05 240);OKLAB uses rectangular coordinates instead of cylindrical: Lightness, a (green-red), b (blue-yellow).
- Value
- oklab(70% 0.1 -0.15)
- Color Space
- oklab
- Gamut
- —
- Contrast Color
-
—
View Code
<color-input value="oklab(70% 0.1 -0.15)" colorspace="oklab" theme="auto"></color-input>Channels
Section titled “Channels”- L (Lightness): 0–100% - Perceived brightness
- a: -0.4 to +0.4 - Green (negative) to red (positive)
- b: -0.4 to +0.4 - Blue (negative) to yellow (positive)
Syntax
Section titled “Syntax”oklab(70% 0.1 -0.15) /* Blue-ish */oklab(85% -0.05 0.1) /* Yellow-green */oklab(50% 0.2 0.05) /* Reddish */When to Use OKLAB
Section titled “When to Use OKLAB”Use OKLAB when:
- You need to blend colors (interpolate in rectangular space)
- Working with color math or transformations
- You prefer Cartesian coordinates over cylindrical
For design work, OKLCH is usually more intuitive.
HSL (Hue, Saturation, Lightness) is familiar to web developers but not perceptually uniform.
- Value
- hsl(240 80% 60%)
- Color Space
- hsl
- Gamut
- —
- Contrast Color
-
—
View Code
<color-input value="hsl(240 80% 60%)" colorspace="hsl" theme="auto"></color-input>Syntax
Section titled “Syntax”hsl(240 80% 60%) /* Blue */hsl(120 100% 50%) /* Pure green */hsl(0 100% 50% / 0.5) /* Semi-transparent red */Limitations
Section titled “Limitations”- Not perceptually uniform - same L value looks different across hues
- Saturation behaves inconsistently
- Can’t represent wide-gamut colors
- Prefer OKLCH for new projects
Standard RGB color space for the web. Supports hex notation.
- Value
- #3b82f6
- Color Space
- srgb
- Gamut
- —
- Contrast Color
-
—
View Code
<color-input value="#3b82f6" colorspace="srgb" theme="auto"></color-input><color-input value="#3b82f6" colorspace="srgb"></color-input>- Value
- rgb(59 130 246)
- Color Space
- srgb
- Gamut
- —
- Contrast Color
-
—
View Code
<color-input value="rgb(59 130 246)" colorspace="srgb" theme="auto"></color-input><color-input value="rgb(59 130 246)" colorspace="srgb"></color-input>When to Use sRGB
Section titled “When to Use sRGB”- Converting existing hex colors
- Compatibility with older systems
- Direct control over display RGB values
For color design, prefer OKLCH.
HWB (Hue, Whiteness, Blackness) is an alternative to HSL, sometimes easier to understand.
- Value
- hwb(240 20% 10%)
- Color Space
- hwb
- Gamut
- —
- Contrast Color
-
—
View Code
<color-input value="hwb(240 20% 10%)" colorspace="hwb" theme="auto"></color-input>hwb(240 20% 10%) /* Blue with some white and black */hwb(120 0% 0%) /* Pure green */LAB & LCH
Section titled “LAB & LCH”CIE LAB and LCH are perceptual color spaces. OKLCH is generally preferred for modern work.
- Value
- lab(70% 20 -40)
- Color Space
- lab
- Gamut
- —
- Contrast Color
-
—
View Code
<color-input value="lab(70% 20 -40)" colorspace="lab" theme="auto"></color-input>- Value
- lch(70% 45 240)
- Color Space
- lch
- Gamut
- —
- Contrast Color
-
—
View Code
<color-input value="lch(70% 45 240)" colorspace="lch" theme="auto"></color-input>Wide Gamut Spaces
Section titled “Wide Gamut Spaces”Wide-gamut RGB spaces for modern displays that exceed sRGB.
Display P3
Section titled “Display P3”Used by modern Apple devices and high-end displays:
- Value
- color(display-p3 0.3 0.7 0.95)
- Color Space
- display-p3
- Gamut
- —
- Contrast Color
-
—
View Code
<color-input value="color(display-p3 0.3 0.7 0.95)" colorspace="display-p3" theme="auto"></color-input>color(display-p3 0.3 0.7 0.95)Rec2020
Section titled “Rec2020”Ultra-wide gamut for HDR and future displays:
color(rec2020 0.3 0.7 0.95)Gamut Detection
Section titled “Gamut Detection”The component automatically detects which gamut contains your color and displays a badge:
- srgb - Fits in standard sRGB
- p3 - Requires Display P3
- rec2020 - Requires Rec2020
- xyz - Beyond Rec2020
Comparison
Section titled “Comparison”- Value
- oklch(70% 0.2 240)
- Color Space
- oklch
- Gamut
- —
- Contrast Color
-
—
Perceptually uniform, intuitive
- Value
- oklab(70% 0.1 -0.15)
- Color Space
- oklab
- Gamut
- —
- Contrast Color
-
—
Perceptually uniform, rectangular
- Value
- hsl(240 80% 60%)
- Color Space
- hsl
- Gamut
- —
- Contrast Color
-
—
Familiar but not uniform
- Value
- rgb(59 130 246)
- Color Space
- srgb
- Gamut
- —
- Contrast Color
-
—
Standard web RGB
- Value
- color(display-p3 0.3 0.7 0.95)
- Color Space
- display-p3
- Gamut
- —
- Contrast Color
-
—
Wide-gamut RGB
Quick Reference
Section titled “Quick Reference”| Color Space | Type | Gamut | Best For |
|---|---|---|---|
| OKLCH | Perceptual | Wide | Design, accessibility, palettes |
| OKLAB | Perceptual | Wide | Color math, blending |
| HSL | Legacy | sRGB | Simple adjustments, legacy code |
| HWB | Legacy | sRGB | Alternative to HSL |
| sRGB | RGB | sRGB | Hex colors, legacy |
| LAB/LCH | Perceptual | Wide | Alternative to OKLCH |
| Display P3 | RGB | P3 | Wide-gamut displays |
| Rec2020 | RGB | 2020 | HDR, future displays |