Course contentsShow
← Web Development
Lesson 494 of 2,9828. Advanced CSS Selectors and FeaturesFree lesson

LAB and OKLAB Color Functions

Explore LAB and OKLAB color spaces that separate lightness from color, enabling more intuitive color manipulation and accessibility.

LAB and OKLAB Color Functions

You'll learn how LAB and OKLAB color spaces separate lightness from color information, making it easier to create accessible and predictable color variations.

What Are LAB and OKLAB?

While traditional color models like RGB mix all color information together, LAB and OKLAB separate lightness (how bright or dark) from color (hue and intensity). This separation mirrors how human vision actually works.

Think of it like adjusting volume versus changing radio stations—lightness is the volume knob (independent), while the other two axes control the "station" (color). This makes predictable adjustments much simpler.

How They Work

Both use three values:

  • L: Lightness (0% = black, 100% = white)
  • a/b: Color axes (positive/negative values for different hues)

LAB is the original, while OKLAB is a refined version with better uniformity—colors that look equally different have more consistent numeric differences.

CSS Syntax

.lab-color {
  /* lab(L a b) */
  background-color: lab(50% 40 59);
}

.oklab-color {
  /* oklab(L a b) */
  background-color: oklab(60% 0.15 -0.09);
}

Why This Matters for Accessibility

Because lightness is separate, you can:

  • Lighten colors for hover states without shifting hue
  • Ensure consistent contrast by adjusting only the L value
  • Create color variations that maintain readability

Example: darkening a button on hover becomes predictable—reduce L by 10%, keep a and b constant, and the color stays recognizably the same, just darker.

Key Takeaway: LAB and OKLAB separate lightness from color, enabling intuitive manipulation like "make this 20% lighter" without accidentally changing the hue or saturation, which greatly benefits accessible color systems.