Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Functions

The hsl() function

Reference for the CSS hsl() function: hue angles, saturation and lightness percentages, alpha, building palettes, and live examples you can edit.

The hsl() function describes a color with hue, saturation and lightness. Hue is the position on the color wheel as an angle, saturation is how vivid the color is, and lightness runs from black through the pure color to white. Because these are closer to how people think about color, hsl() makes it easy to build a palette: keep the hue and change the lightness.

hsla() is an alias that behaves the same way.

CSS
.button {
  background: hsl(220 90% 50%);
  border-color: hsl(220 90% 35%);
}

Try it

One hue, many lightness values

The first row changes only lightness, the second only saturation, the third only hue. Notice that hue 360 lands on the same red as hue 0.

Syntax

CSS
hsl(H S L)
hsl(H S L / A)
hsl(H, S, L)          /* legacy */
hsl(H, S, L, A)       /* legacy */
hsl(from <color> H S L / A)

The result is a <color>, usable anywhere a color is accepted, and it is animatable like any color.

Syntax and arguments

Argument Description
H Hue: a number (read as degrees) or an angle such as 210deg, 0.5turn. It wraps around, so -30 equals 330.
S Saturation: 0% is gray, 100% is the most vivid. Write it with the percent sign.
L Lightness: 0% is black, 100% is white, 50% is the pure color.
A Optional alpha, a number from 0 to 1 or a percentage.
none Modern syntax only: a missing component.

Usage notes

  • Hue positions. Roughly: 0 red, 60 yellow, 120 green, 180 cyan, 240 blue, 300 magenta.
  • Palettes with custom properties. Store the hue once (--hue: 220) and write hsl(var(--hue) 80% 50%); changing one number re-themes a component.
  • Lightness is not perceived brightness. hsl(60 100% 50%) (yellow) looks far lighter than hsl(240 100% 50%) (blue) at the same L, so contrast can differ wildly between hues. For even steps use oklch().
  • Same gamut as rgb(). Every hsl() color is an sRGB color; values outside sRGB are clipped.
  • Check contrast. Always verify text contrast; do not guess from the lightness number.

Browser support

Supported in every browser; the space-separated form with a / alpha is newer, so check a compatibility table if you support old browsers.