RGB to HEX Converter
Enter red, green and blue values or a CSS rgb() string and get the matching HEX color code.
Convert RGB Colors to HEX Codes
Color pickers, image editors and graphics code often report colors as three numbers, while CSS, design tokens and brand guidelines prefer the compact HEX code. Converting RGB to HEX is exact: the same three bytes are simply written in base 16.
This page opens the Color Converter with RGB input selected and an example filled in.
The conversion step by step
- Take each channel value from 0 to 255.
- Divide by 16: the whole number is the first hex digit, the remainder the second (10 to 15 are written A to F).
- Pad single digits with a leading zero, so 10 becomes
0A, notA. - Join the three pairs after a
#.
| RGB | Per channel | HEX |
|---|---|---|
rgb(10, 132, 255) | 0A · 84 · FF | #0A84FF |
rgb(255, 87, 51) | FF · 57 · 33 | #FF5733 |
rgb(128, 128, 128) | 80 · 80 · 80 | #808080 |
Forgetting the zero padding is the classic bug in hand-written converters: 10, 132, 255 joined without padding gives #A84FF, which is not a valid color.
rgba() and 8-digit HEX
CSS has accepted 8-digit HEX codes for years. The fourth pair is alpha: multiply the 0–1 alpha by 255 and round, so 0.5 becomes 128, or 80 in hex. The converter shows both the 8-digit code and the rgba() form, so you can use whichever your tool supports.
RGB to HEX in code
In JavaScript: '#' + [r, g, b].map(v => v.toString(16).padStart(2, '0')).join(''). In Python: '#{:02X}{:02X}{:02X}'.format(r, g, b). Both handle the zero padding for you.
Related tools
Use HEX to RGB for the reverse direction, HEX to HSL when you want to adjust lightness systematically, and the Color Contrast Checker before using a color for text.