CSS Colors
Color in CSS
CSS offers multiple ways to specify colors. Each format has its advantages, and you'll use different ones depending on your needs.
1. Named Colors
CSS has 140 predefined color names like red, blue,
green. Easy to remember but limited.
2. Hexadecimal (Hex) Colors
Hex colors use a # followed by 6 digits (or 3 for shorthand).
Format: #RRGGBB where RR=red, GG=green, BB=blue.
#fff = #ffffff
(white), #000 = #000000 (black)
3. RGB and RGBA
RGB uses red, green, blue values (0-255). RGBA adds an alpha channel for opacity (0-1).
4. HSL and HSLA
HSL stands for Hue (0-360°), Saturation (0-100%), Lightness (0-100%). HSLA adds opacity. More intuitive for color adjustments.
When to Use Each Format
- Hex - Most common, design tools export hex codes
- RGB/RGBA - When you need transparency
- HSL/HSLA - Creating color variations (lighter/darker)
- Named - Quick prototyping or very basic colors
Quick Quiz
Which color format allows you to set transparency?
Enjoying these tutorials?