RGB to HEX

Turn red, green and blue channel values into the hex code stylesheets expect, with alpha where you need it.

HEX#6366f1
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.

Source: W3C CSS Color Module Level 4 — the rgb() function specifies a color in the sRGB color space; hex notation writes the same three channels in base sixteen

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.

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.

Write to us

Opens your mail app with the page and tool already filled in.

Related tools