Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

hsl()

A color by hue, saturation and lightness.

Syntax

hsl(hue saturation lightness / alpha)

Parameters

ParameterTypeDescription
hueangleThe position on the color wheel from 0 to 360: 0 is red, 120 green, 240 blue.
saturationpercentageFrom `0%` (gray) to `100%` (vivid).
lightnesspercentageFrom `0%` (black) to `100%` (white).
alpha0–1After a slash: opacity.

Examples

Shades of one hue — only the lightness changes:

<style>
  div { padding: 8px; color: white; }
</style>
 
<div style="background: hsl(210 80% 30%);">hsl(210 80% 30%)</div>
<div style="background: hsl(210 80% 50%);">hsl(210 80% 50%)</div>
<div style="background: hsl(210 80% 70%);">hsl(210 80% 70%)</div>

Notes

HSL is easy to read and edit by hand. Its drawback: colors with the same lightness do not look equally bright (yellow seems lighter than blue). oklch() fixes this.

See also

  • rgb() — A color from red, green and blue components, with optional transparency.
  • oklch() — A color in the OKLCH space: perceived lightness, chroma and hue.
  • color — The color of the text (and the default color of borders and SVG icons).

In the tutorial

  • Colors — Text and background color, ways to write a color in CSS — names, hex, rgb() and hsl() — and transparency.

Thanks for reading!

Donate to the site — we work hard for you.