Course contentsShow
← Web Development
Lesson 183 of 2,9823. CSS FundamentalsFree lesson

HSL and HSLA Functions

Define colors using hue, saturation, and lightness with hsl() and hsla() for more intuitive color manipulation.

HSL and HSLA Functions

What you'll learn: How to define colors using hue, saturation, and lightness values for more intuitive color control in CSS.

What Are HSL and HSLA?

HSL stands for Hue, Saturation, Lightness—a color model that matches how we naturally think about color. Instead of mixing red, green, and blue channels like rgb(), you describe a color by picking its shade, how vivid it is, and how light or dark it should be.

HSLA adds one more value: Alpha for transparency (just like RGBA).

The Three Components

Hue is the actual color on the color wheel, measured in degrees (0-360):

  • 0° (or 360°) = red
  • 120° = green
  • 240° = blue

Saturation is the intensity or vibrancy, expressed as a percentage:

  • 0% = grayscale (no color)
  • 100% = fully vivid

Lightness is how bright the color is, also a percentage:

  • 0% = black
  • 50% = the pure color
  • 100% = white

Alpha (in hsla()) is transparency from 0 (invisible) to 1 (solid).

Syntax

color: hsl(240, 100%, 50%); /* Bright blue */
color: hsl(120, 50%, 60%);  /* Muted green */
color: hsla(0, 100%, 50%, 0.5); /* Semi-transparent red */

Why Use HSL?

HSL makes it easy to create color variations. Need a lighter version of a color? Just increase the lightness percentage. Want less intensity? Reduce saturation. This intuitive control makes HSL perfect for building color schemes programmatically or adjusting colors quickly.

Key Takeaway: HSL defines colors using hue (0-360°), saturation (0-100%), and lightness (0-100%), offering a more human-friendly way to work with color than mixing RGB channels.