HEX to RGB: How Web Colors Actually Work

Try it yourself: Hex To Rgb tool →

One color, three numbers

Every color on a screen is three values: red, green and blue, each between 0 and 255. A HEX code is those same three values written in base 16 instead of base 10. Two hex digits hold one byte, which is exactly the range 0 to 255, so #2563eb is 0x25 red, 0x63 green and 0xeb blue - that is 37, 99 and 235.

Converting by hand is a two-step multiplication per channel: take the first digit times 16 and add the second digit. For the blue channel above, 'e' is 14 and 'b' is 11, so 14 x 16 + 11 = 235. Once you have done it twice it becomes automatic.

Why #abc is the same as #aabbcc

The three-digit form is shorthand: each digit is duplicated. #29e expands to #2299ee. That is why shorthand can only express colors whose channel values repeat their high and low nibble - it is a convenience for the common cases, not a different format.

Browsers accept both, plus four and eight digit forms where the extra digits carry alpha transparency. An eight-digit code like #2563ebcc is the six-digit color at 80 percent opacity, because 0xcc is 204 and 204/255 is 0.8.

Where HSL fits

RGB is how the screen works; HSL is how people think. Hue is the position on the color wheel in degrees, saturation is how grey the color is, and lightness runs from black through the pure color to white. The same blue #2563eb is hsl(221, 83%, 53%).

That matters when you build a palette: shifting hue by 30 degrees gives an analogous color, 180 gives the complement, and adjusting only lightness gives a usable set of surfaces. Editing an RGB triple directly rarely produces a coherent result.

About this guide
Written and maintained by the ColorLab editorial team. We test each method on real data before publishing, link to the tool that automates it, and revise the page when the underlying standard changes.
Sponsored — ad slot reserved

More guides

Free tools mentioned