The following example shows how to specify a color space when interpolating colors in repeating gradients. Three boxes show different types of repeating gradients using the repeating-conic-gradient()
, repeating-linear-gradient()
, and repeating-radial-gradient()
functions. The first box uses the Lab color space to interpolate between two color values. The second and third boxes use Oklch and additionally provide a <hue-interpolation-method>
to specify how to interpolate between hue values.
HTML
<div class="gradient conic">conic</div>
<div class="gradient linear">linear</div>
<div class="gradient radial">radial</div>
CSS
We used the same two colors in each gradient to demonstrate the different effects of <hue-interpolation-method>
and color space on color interpolation in gradients.
.conic {
background-image: repeating-conic-gradient(
in lab,
burlywood,
blueviolet 120deg
);
}
.linear {
background-image: repeating-linear-gradient(
in oklch,
burlywood,
blueviolet 75px
);
}
.radial {
background-image: repeating-radial-gradient(
in oklch longer hue,
blueviolet 50px,
burlywood 100px
);
}
Result
Comparing the first and second boxes demonstrates the difference of interpolating between two colors in differing color spaces. Comparing the second and third boxes shows the difference between <hue-interpolation-method>
s, with the linear gradient using the shorter method (default) and the radial gradient using the longer method.