RGB to hex

Each channel becomes two hex digits, zero-padded. Values are rounded to the nearest integer first.

Hue
Alpha
100%
hex
#4287f5

Paste a RGB value — other formats work too.

Need every format at once? Open in the full picker

Worked examples

Common colours converted from RGB to hex, computed with the same engine the picker uses.

ColourRGBhexCopy
Pure redrgb(255 0 0)#ff0000
Pure greenrgb(0 255 0)#00ff00
Pure bluergb(0 0 255)#0000ff
Whitergb(255 255 255)#ffffff
Mid greyrgb(128 128 128)#808080
Blackrgb(0 0 0)#000000
Interface bluergb(66 135 245)#4287f5
Success greenrgb(34 197 94)#22c55e
Danger redrgb(239 68 68)#ef4444
Warning amberrgb(245 158 11)#f59e0b
Editor blackrgb(30 30 30)#1e1e1e
Warm sandrgb(233 196 106)#e9c46a

How the conversion works

Each channel becomes two hex digits, zero-padded. Values are rounded to the nearest integer first.

Both formats are computed from a single canonical representation — CIE XYZ with a D65 white point, held in floating point — rather than by chaining one format into the next. That matters because chained conversions accumulate rounding error, and because it means a colour that cannot be represented in the target format is handled deliberately rather than by accident.

When the source describes a colour outside the target's gamut, chroma is reduced in OKLCh while lightness and hue are held, following the CSS Color 4 gamut mapping algorithm. Clipping each channel independently would be simpler but visibly shifts hue on saturated colours.

Related conversions