HEX, RGB and HSL: what each color code means
HEX, RGB and HSL can all describe the same color. They differ in how easy they are to read and adjust.
RGB
Screens mix red, green and blue light. In rgb(42, 127, 158), each number runs from 0 to 255. Zero for all three is black, and 255 for all three is white. RGB is exact, but it is hard to guess a color from its numbers.
HEX
HEX writes the same three values in base 16. #2A7F9E means red 2A, green 7F and blue 9E. It is compact, which is why design tools and brand guides use it. The short form #FA0 expands to #FFAA00.
HSL
HSL describes color the way people tend to think about it. Hue is the position on the color wheel from 0 to 360. Saturation is how vivid it is, and lightness runs from black to white.
This makes changes easy. To create a hover state, reduce the lightness a little and leave everything else alone. To build a set of tints, keep hue and saturation fixed and step through lightness.
Which should you use?
Use HEX for handing colors to other people, and HSL when you are building scales or variations. Some newer CSS formats such as OKLCH give more even lightness across hues, but HEX and HSL remain the most widely understood.
Keep reading
- How to choose a brand color palette in five steps
A practical way to pick a main color, supporting colors and neutrals that work on real screens.
- The 60-30-10 color rule, with examples
A simple ratio for balancing colors in layouts, and when you should ignore it.
- Color contrast and WCAG, explained without the jargon
What contrast ratios mean, which numbers to aim for and how to fix colors that fail.