🎨 CSS Tutorial: lab() & lch() Color Functions

πŸ“Œ Introduction

The lab() and lch() color functions in CSS belong to the modern CSS Color Level 4 specification. These functions provide perceptually uniform color spaces β€” meaning colors behave more naturally to human vision compared to RGB or HSL. They are excellent for design systems, gradients, color interpolation, and ensuring accessible contrast. 🌈✨

🎯 Why Use lab() & lch()?

  • More accurate representation of human color perception
  • Better contrast handling (ideal for accessibility)
  • Consistent color mixing & interpolation
  • Better for gradients and UI design tokens
>>β€œLCH and LAB are how designers wish digital colors behaved by default.”

✨ Syntax Overview

lab() Syntax

color: lab(<lightness> <a> <b> / <alpha>?);

lch() Syntax

color: lch(<lightness> <chroma> <hue> / <alpha>?);

Note

Both functions support an optional alpha value using /. Example β†’ lch(70% 50 30 / 0.6)

🧩 Understanding LAB & LCH

πŸ”Έ lab()

  • L β†’ Lightness (0% = black, 100% = white)
  • a β†’ Green (βˆ’) ↔ Red (+)
  • b β†’ Blue (βˆ’) ↔ Yellow (+)

lab() Example

color: lab(60% 40 -20);

πŸ”Έ lch()

  • L β†’ Lightness (0%–100%)
  • C β†’ Chroma (color intensity)
  • H β†’ Hue (angle in degrees: 0–360)

lch() Example

color: lch(70% 60 240);

Note

lch() is easier to use because it behaves like HSL but with better accuracy.

πŸ”₯ Practical Examples

1. Soft Accessible Text Color

Accessible Text

.text {
  color: lab(30% 0 0); /* dark neutral */
}

2. Bright, High-Chroma Color

High Chroma

.button {
  background: lch(70% 80 40);
}

3. Color with alpha transparency

Alpha

color: lch(60% 40 200 / 0.4);

4. Gradient Using lch()

LCH Gradient

.gradient {
  background: linear-gradient(
    to right,
    lch(70% 60 10),
    lch(70% 60 300)
  );
}

5. Neutral Tone Palette (lab space)

Neutral Palette

.neutral {
  background: lab(85% 0 0); /* light neutral */
}

6. Vibrant Design Tokens

Tokens

:root {
  --primary: lch(65% 75 260);
  --secondary: lch(60% 70 40);
  --accent: lch(80% 90 340);
}

πŸ“Š LAB vs LCH vs HSL vs RGB

Color SpaceBest ForStrength
lab()Neutral & balanced colorsPerceptually uniform
lch()Design palettes, gradientsHue-based & vibrant
hsl()Simple hue-based selectionEasy to read
rgb()Precise raw color valuesWorks everywhere

🧠 Tips for Using lab() & lch()

  • Use lch() for UI colors (vibrant, clean, consistent)
  • Use lab() for neutrals, grayscale, and accessible color choices
  • Use chroma (C) carefully β€” too high may cause out-of-gamut colors
  • If colors appear dull, increase the chroma value in lch()
  • Use oklch() when you want even better perceptual uniformity (newer color space)

πŸ–ΌοΈ Visual Demo

πŸŽ‰ Conclusion

The lab() and lch() color functions bring high-precision, perceptually-uniform color control to CSS. They outperform RGB and HSL for gradients, palettes, accessibility, and design systems. Mastering these functions lets you craft UI colors that look natural, vibrant, and consistent across light and dark themes. These are the future of color on the web β€” start using them today! πŸš€