RGB to HEX

Paste any rgb() or rgba() value and copy the matching HEX color.

HEX
#4F46E5
RGB
rgb(79, 70, 229)
RGBA
rgba(79, 70, 229, 1)
HSL
hsl(243, 75%, 59%)
HSV
hsv(243, 69%, 90%)
CMYK
cmyk(66%, 69%, 0%, 10%)
CSS Variable
--color-primary: #4F46E5;

About the rgb to hex

RGB describes a color through its red, green and blue channels — three integers from 0 to 255. HEX is the same data encoded as two hexadecimal digits per channel, which is shorter and is the standard way of writing colors in CSS files.

To convert, take each channel and turn it into base 16, padded with a leading zero if necessary. rgb(79, 70, 229) becomes #4F46E5.

Frequently asked questions

What is the formula to convert RGB to HEX?+

Convert each channel (0–255) to base 16, pad to two digits, and concatenate red, green and blue. Add a # prefix.

Can I convert RGBA to HEX with alpha?+

Yes. Modern CSS supports 8-digit HEX values where the last two digits encode alpha from 00 to FF.

Should I use HEX or RGB in CSS?+

Either works. HEX is more compact and ubiquitous; RGB is more readable and is required when you compute colors at runtime or use alpha.

Are the colors identical?+

Yes. RGB and HEX are two different notations for exactly the same color value — there is no precision loss.

Related tools