CSS Data Type - <color-interpolation-method>



CSS <color-interpolation-method> data type determines the color space used when creating a transition between different <color> values. This data type overrides the default color blending for functions such as, color-mix() and linear-gradient().

The interpolation color space defaults to Oklab, while interpolating color values.

Possible Values

  • <rectangular-color-space> − Keywords srgb, srgb-linear, lab, oklab, XYZ, XYZ-D50, or XYZ-D65 can be used.

  • <polar-color-space> − Keyword shsl, hwb, lch, or oklch can be used.

  • <hue-interpolation-method> − The algorithm for interpolating hue. It defaults to the shorter hue. It is optional.

Syntax

<color-interpolation-method>: <rectangular-color-space> | <polar-color-space> | <hue-interpolation-method>;

CSS <color-interpolation-method> - linear-gradient()

The following example demonstrates the use of different color spaces and gradient interpolations using linear-gradient()

<html>
<head>
<style>
   .srgb-gradient {
      background-image: linear-gradient(
      to right,
      rgb(15, 73, 27),
      rgb(160, 214, 173),
      rgb(63, 138, 13),
      rgb(34, 180, 66),
      rgb(79, 236, 132),
      );
   }
   .oklab-gradient {
      background-image: linear-gradient(
      to right,
      oklab(45.2% -0.032 -0.312),
      oklab(48.7% 0.019 -0.224),
      oklab(52.2% 0.07 -0.137),
      oklab(55.8% 0.122 -0.049),
      oklab(59.3% 0.173 0.038),
      oklab(62.8% 0.225 0.126)
      );
   }
   .oklch-longer-gradient {
      background-image: linear-gradient(
      to right,
      oklch(45.2% 0.313 264),
      oklch(46.8% 0.308 243),
      oklch(48.4% 0.303 221),
      oklch(50% 0.298 200),
      oklch(51.6% 0.293 179),
      oklch(53.2% 0.288 157),
      oklch(54.8% 0.283 136),
      oklch(56.4% 0.278 115),
      oklch(58% 0.273 93),
      oklch(59.6% 0.268 72)
      );
   }
   .gradient {
      height: 60px;
      width: 50%;
   }
   .srgb-gradient {
      background-image: linear-gradient(in srgb to right, green, yellow);
   }
   .oklab-gradient {
      background-image: linear-gradient(in oklab to right, green, yellow);
   }
   .oklch-longer-gradient {
      background-image: linear-gradient(in oklch longer hue to right, green, yellow);
   }
</style>
</head>
<body>
   <div>sRGB:</div>
   <div class="gradient srgb-gradient"></div>
   <div>Oklab:</div>
   <div class="gradient oklab-gradient"></div>
   <div>Oklch Gradient (with longer hue):</div>
   <div class="gradient oklch-longer-gradient"></div>  
</body>
</html>
Advertisements