Look at these three lines of CSS: #2563EB, rgb(37, 99, 235), and hsl(221, 83%, 53%). On screen, all three paint the exact same royal blue pixel. None of them has a wider color range or better browser performance. The real difference is human readability and maintainability.
1. RGB: Direct Hardware Control
RGB stands for Red, Green, Blue, with each channel ranging from 0 (completely off) to 255 (maximum brightness). It mirrors how screen hardware works and is easy to read when troubleshooting brightness:
rgb(0, 0, 0)is pure black;rgb(255, 255, 255)is pure white.- Whenever all three numbers are equal (like
rgb(128, 128, 128)), the color is a pure neutral gray. - Need transparency? Modern CSS supports slash syntax directly inside RGB:
rgb(37 99 235 / 0.2)or the classicrgba(37, 99, 235, 0.2).
2. HEX: Compact Shorthand for RGB
A HEX code is simply an RGB value compressed into base-16 (hexadecimal) notation using digits 0–9 and letters A–F. The six characters split cleanly into three pairs: #RRGGBB.
Each pair calculates as (first digit × 16) + second digit:
00equals0(minimum intensity).80equals8 × 16 + 0 = 128(halfway).FFequals15 × 16 + 15 = 255(maximum intensity).
Pro tip on shorthand & alpha: When every pair repeats (like #FF8800), CSS lets you shorten it to 3 digits (#F80). You can also add two extra digits at the end for opacity—for example, #2563EB80 sets 50% transparency.
3. HSL: Built for Human Intuition
Try looking at #2563EB and mentally making it 12% darker for a button hover state—it is nearly impossible without opening a picker. That is why designers and front-end engineers love HSL (Hue, Saturation, Lightness):
- Hue (0°–360°): The position on the color wheel.
0°is red,120°is green,240°is blue, and360°loops back to red. - Saturation (0%–100%): Color intensity.
0%removes all chroma (leaving pure gray), while100%is maximally vivid. - Lightness (0%–100%): Brightness.
0%is always black,50%is the pure hue, and100%is always white.
Side-by-Side Examples
| Color | HEX | RGB | HSL |
|---|---|---|---|
| Coral | #FF7F50 |
rgb(255, 127, 80) |
hsl(16, 100%, 66%) |
| Royal Blue | #2563EB |
rgb(37, 99, 235) |
hsl(221, 83%, 53%) |
| Sea Green | #2E8B57 |
rgb(46, 139, 87) |
hsl(146, 50%, 36%) |
| Rebecca Purple | #663399 |
rgb(102, 51, 153) |
hsl(270, 50%, 40%) |
Building a Cohesive UI Scale With HSL
One of the cleanest CSS tricks is storing your brand's Hue and Saturation once, then shifting only Lightness to generate an entire palette of backgrounds, borders, buttons, and hover states that never clash:
- Soft tint background:
hsl(221, 83%, 96%) - Subtle border:
hsl(221, 70%, 82%) - Primary button:
hsl(221, 83%, 53%) - Hover state:
hsl(221, 83%, 44%)(just drop Lightness by 9%) - Dark accent text:
hsl(221, 80%, 28%)
Which Format Should You Pick?
- Use HEX for copy-pasting static brand codes between Figma, Slack, and brand PDFs.
- Use RGB when manipulating pixel buffers in HTML Canvas, WebGL, or image-processing code.
- Use HSL in CSS custom properties whenever you are building themes, dark modes, hover states, or multi-shade component libraries.