HEX to RGB Converter
Paste a HEX color code and get its RGB values, ready to copy as rgb() or rgba().
Convert HEX Color Codes to RGB
Design files and brand guides usually give colors as HEX codes, while canvas code, SVG attributes, image libraries and CSS with transparency often want RGB numbers. The two notations describe exactly the same thing, so converting between them is lossless.
This page opens the Color Converter with HEX input selected and an example loaded. Replace it with your own code.
How the conversion works
A HEX color is three bytes written in base 16: red, green and blue. Each pair of digits ranges from 00 to FF, which is 0 to 255 in decimal. To convert a pair, multiply the first digit by 16 and add the second, where A to F stand for 10 to 15.
| HEX | Pairs | RGB |
|---|---|---|
#0A84FF | 0A · 84 · FF | rgb(10, 132, 255) |
#FF5733 | FF · 57 · 33 | rgb(255, 87, 51) |
#FFF | FF · FF · FF | rgb(255, 255, 255) |
#000000 | 00 · 00 · 00 | rgb(0, 0, 0) |
Short codes and alpha
- 3 digits: every digit is doubled, so
#0AFis#00AAFF. - 4 digits: the same doubling, with the fourth digit as alpha.
- 8 digits: the last pair is alpha from 00 (transparent) to FF (opaque), shown as
rgba()with a 0–1 value. - The leading
#is optional; lowercase and uppercase both work.
HEX to RGB in code
In JavaScript, parseInt('84', 16) returns 132, so a full conversion is three such calls on the pairs. In Python, tuple(int(h[i:i+2], 16) for i in (0, 2, 4)) does the same for a six-digit string without the #. Modern CSS accepts both notations directly, so a conversion is only needed when a tool or API insists on one of them.
Related conversions
Going the other way, RGB to HEX turns channel values back into a code. For building lighter and darker variants, HEX to HSL is usually more convenient, and the Color Contrast Checker tells you whether a color is readable on its background.