RGB to HEX Converter

Type an rgb() value (or three numbers) to get the HEX code. Alpha values produce 8-digit HEX. Everything runs in your browser.

HEX
#2D5BE3
HEX with alpha
#2D5BE3FF
CSS rgb()
rgb(45 91 227)
HSL
hsl(225, 76%, 53%)

How RGB to HEX conversion works

Each RGB channel is a number from 0 to 255. HEX writes the same number in base 16, which needs exactly two digits (00 to FF). The three pairs are joined in red, green, blue order after a #.

rgb(45, 91, 227)
45  ÷ 16 = 2 rest 13  → 2D
91  ÷ 16 = 5 rest 11  → 5B
227 ÷ 16 = 14 rest 3  → E3
= #2D5BE3

Going the other way? Use the HEX to RGB converter. For print values, see HEX to CMYK.

Common RGB and HEX values

ColorRGBHEX
Blackrgb(0, 0, 0)#000000
Whitergb(255, 255, 255)#FFFFFF
Redrgb(255, 0, 0)#FF0000
Lime (pure green)rgb(0, 255, 0)#00FF00
Bluergb(0, 0, 255)#0000FF
Yellowrgb(255, 255, 0)#FFFF00
Cyanrgb(0, 255, 255)#00FFFF
Magentargb(255, 0, 255)#FF00FF
Gray (CSS gray)rgb(128, 128, 128)#808080
Orange (CSS orange)rgb(255, 165, 0)#FFA500

Frequently asked questions

How do you convert RGB to HEX?

Convert each channel (0-255) to a two-digit base-16 number and join them after a #. For rgb(45, 91, 227): 45 = 2D, 91 = 5B, 227 = E3, so the HEX code is #2D5BE3.

What about transparency?

CSS supports 8-digit HEX (#RRGGBBAA). The last pair is the alpha channel: alpha 0.5 is 0.5 × 255 = 127.5, which rounds to 128 = 80, so rgba(255, 0, 0, 0.5) becomes #FF000080.

Is HEX the same color as RGB?

Yes. HEX and rgb() are two notations for exactly the same sRGB color; converting between them loses nothing (apart from alpha rounding to 1/255 steps).