A gradient from blue to purple is shown represented 4 ways, shorter, longer, increasing and decreasing.
My google avatar.2 min read

Gradient hue interpolation

css
3,545 views

When a gradient needs to transition from one color to the next, it takes the shortest route it can. But what if the result of that stinks?

A circle gradient representing all hues and is white in the center, where a smaller inner circle shows the difference between shorter and longer routes

Hue interpolation #

That's where new CSS gradient syntax from Color 4 for hue interpolation comes in. Here I specify the gradient takes the longer route:

.gradient-with-hue-interpolation-specified {
  background: linear-gradient(
    to right in hsl longer hue, 
    oklch(63% 0.3 317), 
    oklch(63% 0.2 255)
  );
}

It's almost like the browser has been Zoolander this whole time, it would only turn right ๐Ÿ˜‚

Here's 2 demo's that use ColorJS to help illustrate the effects of this hue interpolation choice. Aka, demo's that help the browser turn left hehe.

Blue to Purple example #

A soft intro example into the topic:

Interactive demo #

This one let's you pick the colors and number of steps:

So so many more color tools coming to the browser!

4 comments #

83likes

tianenpang, DamienSchweich, BlancoPancho and 56 more

9reposts
  • Maurรญcio '๐˜ฑ๐˜ข๐˜ณ๐˜ฐ๐˜ฅ๐˜บ' ๐Ÿง
  • David
  • Diego๐Ÿ›ธ
  • Juk
  • Zimmer
  • Alena Nikolaeva โœจ
  • Articulated Dev
  • Bjoern Sellnau
  • Adam Josefus ๐Ÿง‰

Join the conversation on

Thanks for sharing ๐Ÿ™ this helps figuring out where to go. Creating tile backgrounds right now. Also that article title effect is dope
moji ///moji ///
thanks yo! rock on!
Adam ArgyleAdam Argyle
You say โ€œit would only turn rightโ€. Has there been a way to get gradients to go around the hue circle before now? My gradients always seem to dip through grey instead. (If it's just for the joke, then my bad ๐Ÿ˜…)
Brook JordanBrook Jordan
You can guide it away from the center by adding more color stops ๐Ÿ‘๐Ÿป Here's a great tool! dribbble.com/shots/15186722โ€ฆ
Adam ArgyleAdam Argyle