HEX to RGB
Convert a hex colour to its red, green and blue channels, including the shorthand and alpha forms defined by the CSS specification.
- HEX
- #6366f1
- RGB
- rgb(99 102 241)
- HSL
- hsl(238.73 83.53% 66.67%)
- OKLCH
- oklch(0.5854 0.2041 277.12)
A hex colour is just three bytes written in base sixteen, one per channel, which is why #ff0000 is pure red and #000000 is black. The shorthand catches people out: #123 is not a darker version of anything, it is literally #112233, because the specification expands each digit by duplicating it rather than padding it with a zero. Everything is parsed in your browser.
How it is calculated
R = int(hex[0:2], 16), G = int(hex[2:4], 16), B = int(hex[4:6], 16)
Each pair of hex digits becomes a number from 0 to 255. A fourth pair, when present, is the alpha channel and is divided by 255 to give the 0 to 1 value that CSS expects.
Questions people ask
- Why does #123 equal #112233 rather than #012030?
- Because the specification expands the shorthand by duplicating each digit, not by padding with zeros. The wording is explicit: "the notation #123 specifies the same color as the notation #112233".
- What does the eight digit form mean?
- The last pair is alpha, from 00 for fully transparent to ff for fully opaque. So #00000080 is black at roughly 50 percent opacity — 128 out of 255, which CSS writes as 0.502.
- Is uppercase or lowercase correct?
- Both. Hex digits are case insensitive, so #FF0000 and #ff0000 are the same colour. Lowercase is the more common convention in stylesheets.
Related tools
RGB to HEX
Turn red, green and blue channel values into the hex code stylesheets expect, with alpha where you need it.
HEX to HSL
Convert a hex colour into hue, saturation and lightness — the form that makes a colour easy to lighten, darken or desaturate by hand.
HEX to OKLCH
Convert a hex colour to OKLCH, the perceptual colour space where equal changes in lightness actually look equal.
Found a problem, or want more?
A number that disagrees with its source is a defect, not a rounding preference.
What did you enter, what did the tool show, and what did you expect instead? If you have a source that disagrees with ours, a link to it is the most useful thing you can send.
Opens your mail app with the page and tool already filled in.