Read more

Sass function to set a color to an absolute hue

Arne Hartherz
July 07, 2014Software engineer at makandra GmbH

The adjust-hue function Show archive.org snapshot of Sass allows you to change a color's hue, but only relative to its current hue.

adjust-hue(#ffff00, 120)
// => #00ffff
adjust-hue(#444400, 120)
// => #004444
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

As you can see, we moved our yellow by 120° to cyan. \
But what if you want to move any color to a hue of 120° which is a nice shiny green?

Take this function:

@function set-hue($color, $target-hue)
  $current-hue: hue($color)
  $degrees: $target-hue - $current-hue
  @return adjust-color($color, $hue: $degrees)

It now works as expected:

adjust-hue(#ffff00, 120)
// => #00ff00
adjust-hue(#444400, 120)
// => #004400
Posted by Arne Hartherz to makandra dev (2014-07-07 18:12)