SASS calculate HSL Difference between 2 colours

You can check out the following resource:

Building Color Palettes with SASS

Basically, here’s the meat of it:

@function color-diff($a, $b) {
  $sat: saturation($a) - saturation($b);
  $lig: lightness($a) - lightness($b);
  $fn-sat: if($sat > 0, 'desaturate', 'saturate');
  $fn-lig: if($lig > 0, 'darken', 'lighten');
 
  @return (
    adjust-hue: -(hue($a) - hue($b)),
    #{$fn-sat}: abs($sat),
    #{$fn-lig}: abs($lig)
  );
}

You want to do this with a function in SASS (or a parameterized mixin in LESS), and you can see the structure of one above.

Hope this helps.

Leave a Comment