CSS provides multiple ways to specify colors. Let's explore each method!
CSS supports 140+ named colors. Easy to remember but limited options.
Format: #RRGGBB - Two hex digits (00-FF) for Red, Green, Blue
Shorthand: #f00 = #ff0000 (when pairs are same)
Format: rgb(red, green, blue) - Values from 0-255
Format: rgba(red, green, blue, alpha) - Alpha is 0 (transparent) to 1 (opaque)
Format: hsl(hue, saturation%, lightness%)
Create smooth color transitions
background: linear-gradient(to right, #ff6b6b, #feca57);
background: linear-gradient(135deg, #667eea, #764ba2);
background: radial-gradient(circle, #74b9ff, #0984e3);
| Format | Example | Use Case |
|---|---|---|
| Named | red, blue, coral |
Quick prototyping, readability |
| Hex | #ff6b6b |
Most common, compact, design tools |
| RGB | rgb(255, 107, 107) |
Programmatic manipulation |
| RGBA | rgba(255, 107, 107, 0.5) |
When you need transparency |
| HSL | hsl(4, 100%, 71%) |
Creating color variations easily |