Dwarves
Memo
Type ESC to close search bar

HSL Color

Frontend engineers use Hexadecimal color codes to represent colors, but they have some limitations:

HSL is the answer to resolving all of the painful points.

What is HSL?

HSL stands for hue, saturation, and lightness. It’s based on the RGB color wheel. Each color has an angle and a percentage value for the saturation and lightness values.

Using HSL

Darker/lighter colors

Imagine you’re creating a button component and you want it to appear darker on hovering to increase its contrast. You can do this easily with the help of HSL.

:root {
  /* brand color: #E13F5E */
  --primary-h: 349;
  --primary-s: 73%;
  --primary-l: 56%;
}

.button {
  background-color: hsl(var(--primary-h), var(--primary-s), var(--primary-l));
}

.button:hover {
  --primary-l: 40%;
}

Color palette

By altering the lightness, we can create a set of shades for a color that can be used throughout the UI where possible.

HSL transparency (HSLa)

It works exactly the same as with RGB, just add alpha channel with a value from 0 to 1. 0 is fully transparent. 1 is fully opaque. 0.5 is 50% transparent.

hsla(349, 73%, 56%, 0.5)

References