RGB to HEX
Turn red, green and blue channel values into the hex code stylesheets expect, with alpha where you need it.
- HEX
- #6366f1
- RGB
- rgb(99 102 241)
- HSL
- hsl(238.73 83.53% 66.67%)
- OKLCH
- oklch(0.5854 0.2041 277.12)
Going from RGB to hex is the same three numbers written differently: each channel becomes two hex digits. The reason designers keep asking for it is that tooling disagrees — colour pickers and screen readers speak in decimal channels, stylesheets and design files in hex. Nothing is sent anywhere; the conversion happens as you type.
How it is calculated
hex = "#" + pad(R, 16) + pad(G, 16) + pad(B, 16)
Each channel is written in base sixteen and padded to two digits, so 17 becomes 11 and 255 becomes ff. Alpha, when it is not fully opaque, is multiplied by 255 and appended as a fourth pair.
Questions people ask
- What happens to values above 255?
- They are clamped. A channel is one byte, so 300 becomes 255 — the brightest that channel can be.
- Why did my alpha disappear?
- Fully opaque colours are written without the alpha pair, because #ff0000 and #ff0000ff are the same colour and the shorter form is the convention.
- Can I paste the old comma syntax?
- Yes. rgb(255, 0, 0) and rgb(255 0 0) both parse — the numbers are read in order regardless of the separators around them.
Related tools
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.
RGB to HSL
Convert red, green and blue channels into hue, saturation and lightness, the form that says what a colour actually is.
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.