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

Color Interpolation and Gradients in Modern Color Spaces

Control how colors blend in gradients by specifying interpolation in LCH, OKLCH, or other spaces for smoother transitions.

Color Interpolation and Gradients in Modern Color Spaces

What you'll learn: How to control the way colors blend in CSS gradients by specifying which color space to use, creating smoother and more perceptually pleasing transitions.

Why Color Space Matters for Gradients

When you create a gradient, the browser must calculate all the intermediate colors between your start and end points. By default, browsers interpolate (blend) colors in the sRGB color space, which can sometimes produce muddy or unexpected results—especially with vivid colors or complementary hues.

Modern CSS lets you specify which color space to use for this blending. Think of it like choosing different brushes for painting: each color space creates a different path through the color spectrum.

Specifying Interpolation Space

You can add an interpolation method to gradient functions using the in keyword followed by a color space name:

.gradient {
  background: linear-gradient(
    in oklch,
    blue,
    yellow
  );
}

This tells the browser: "blend these colors through the OKLCH color space," which often produces more vibrant, perceptually uniform transitions than the default sRGB.

Common Interpolation Spaces

  • in srgb — Default, sometimes produces muddy mid-tones
  • in oklch — Perceptually uniform, maintains brightness
  • in lch — Similar benefits to OKLCH
  • in lab — Another perceptually uniform option
  • in display-p3 — For wide-gamut displays
/* Compare these two gradients */
.default {
  background: linear-gradient(red, cyan); /* muddy gray middle */
}

.improved {
  background: linear-gradient(in oklch, red, cyan); /* vibrant middle */
}

Key Takeaway: Control gradient color blending by adding in <color-space> to your gradient functions—OKLCH and LCH typically produce smoother, more predictable transitions than the default sRGB interpolation.