HSL colors let you pick colors by choosing their hue, saturation, and lightness. This makes it easy to create and adjust colors in a way that feels natural.
HSL colors in CSS
Start learning this pattern below
Jump into concepts and practice - no test required
hsl(hue, saturation%, lightness%)
Hue is a number from 0 to 360 that represents the color angle on the color wheel (like red, green, blue).
Saturation is a percentage that shows how intense the color is (0% is gray, 100% is full color).
Lightness is a percentage that shows how light or dark the color is (0% is black, 100% is white).
color: hsl(0, 100%, 50%);
color: hsl(120, 100%, 25%);
color: hsl(240, 50%, 75%);
color: hsl(60, 0%, 50%);
This page shows four colored boxes using HSL colors: bright red, dark green, light blue, and medium gray. The background and text also use HSL colors for a soft look. Each box has an accessible label describing its color.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>HSL Colors Example</title> <style> body { font-family: Arial, sans-serif; padding: 2rem; background-color: hsl(210, 30%, 95%); color: hsl(210, 50%, 20%); } .color-box { width: 8rem; height: 8rem; margin: 1rem; border-radius: 0.5rem; display: inline-block; box-shadow: 0 0 5px hsl(0, 0%, 70%); } .red { background-color: hsl(0, 100%, 50%); } .green { background-color: hsl(120, 100%, 25%); } .blue { background-color: hsl(240, 50%, 75%); } .gray { background-color: hsl(0, 0%, 60%); } h1 { color: hsl(210, 80%, 40%); } </style> </head> <body> <h1>HSL Colors Example</h1> <div class="color-box red" aria-label="Bright red color"></div> <div class="color-box green" aria-label="Dark green color"></div> <div class="color-box blue" aria-label="Light blue color"></div> <div class="color-box gray" aria-label="Medium gray color"></div> </body> </html>
You can use hsla() to add transparency with an alpha value (0 to 1).
Hue values wrap around, so 0 and 360 are both red.
Using HSL makes it easy to create color variations by changing lightness or saturation.
HSL colors use hue, saturation, and lightness to define colors.
This model is easy to understand and adjust compared to RGB.
HSL is great for creating color themes and smooth color changes.
Practice
hsl(120, 100%, 50%) color represent in CSS?Solution
Step 1: Understand the HSL parameters
The first value (120) is the hue, which represents green on the color wheel.Step 2: Interpret saturation and lightness
Saturation is 100%, meaning full color intensity, and lightness is 50%, meaning normal brightness.Final Answer:
A bright green color -> Option AQuick Check:
Hue 120° = green, full saturation and medium lightness = bright green [OK]
- Confusing hue degrees with RGB values
- Mixing up saturation and lightness effects
- Assuming 100% lightness means white
Solution
Step 1: Recall CSS function syntax
CSS functions use parentheses () with comma-separated values inside.Step 2: Check each option's syntax
background-color: hsl(240, 100%, 50%); uses parentheses and commas correctly; others use brackets, braces, or missing parentheses.Final Answer:
background-color: hsl(240, 100%, 50%); -> Option AQuick Check:
HSL uses parentheses and commas in CSS [OK]
- Using square brackets or curly braces instead of parentheses
- Omitting commas between values
- Writing HSL values without parentheses
color: hsl(0, 0%, 50%);
Solution
Step 1: Analyze hue and saturation values
Hue is 0°, but saturation is 0%, meaning no color saturation (gray scale).Step 2: Interpret lightness value
Lightness is 50%, which is medium brightness gray.Final Answer:
Medium gray -> Option BQuick Check:
Saturation 0% means gray, lightness 50% = medium gray [OK]
- Ignoring saturation and assuming hue affects color
- Confusing lightness with saturation
- Thinking 0% saturation still shows color
p { color: hsl(360, 120%, 50%); }Solution
Step 1: Check hue value range
Hue can be 0 to 360 degrees; 360 is valid (same as 0).Step 2: Check saturation and lightness ranges
Saturation must be between 0% and 100%; 120% is invalid.Final Answer:
Saturation cannot be more than 100% -> Option DQuick Check:
Saturation max is 100% in HSL [OK]
- Thinking hue cannot be 360
- Ignoring invalid saturation values
- Assuming missing semicolon causes error here
Solution
Step 1: Understand the goal of smooth hue transition
Hue should animate from 0° (red) to 120° (green) with saturation and lightness fixed.Step 2: Check each option's saturation and lightness
@keyframes colorChange { from { color: hsl(0, 100%, 50%); } to { color: hsl(120, 100%, 50%); } } keeps saturation 100% and lightness 50%, which produces vivid colors. Others have incorrect saturation or lightness values causing dull or black colors.Final Answer:
@keyframes colorChange { from { color: hsl(0, 100%, 50%); } to { color: hsl(120, 100%, 50%); } } -> Option CQuick Check:
Animate hue 0° to 120° with full saturation and medium lightness [OK]
- Changing saturation or lightness during hue animation
- Using 0% lightness which results in black
- Using 0% saturation which results in gray
