RGB to HEX Converter
Enter red, green and blue values from 0 to 255 — or paste an rgb() value — and get the HEX code instantly.
How to Convert RGB to HEX
Convert each channel (0–255) into a two-digit hexadecimal number, then join them after a #.
- Divide the value by 16. The whole number is the first digit; the remainder is the second.
- Use letters for 10–15: A, B, C, D, E, F.
- Example for
rgb(108, 92, 231): 108 = 6×16 + 12 →6C; 92 = 5×16 + 12 →5C; 231 = 14×16 + 7 →E7. - Result:
#6C5CE7.
Values below 16 need a leading zero: 9 becomes 09, so rgb(9, 9, 9) is #090909.
RGBA to HEX
Transparency can be written as an 8-digit HEX code. The alpha percentage is converted to 0–255 and then to hex: 50% → 128 → 80, so rgba(108, 92, 231, 0.5) becomes #6C5CE780.
Short HEX Codes
When each pair has two identical digits, the code can be shortened: #FF8800 → #F80. The tool shows the short form when it exists.
Need to go the other way? Use the HEX to RGB Converter, or convert to HSL with the Color Converter.
Common Conversions
| Color | HEX | RGB |
|---|---|---|
#000000 | rgb(0, 0, 0) | |
#FFFFFF | rgb(255, 255, 255) | |
#FF0000 | rgb(255, 0, 0) | |
#00FF00 | rgb(0, 255, 0) | |
#0000FF | rgb(0, 0, 255) | |
#FFFF00 | rgb(255, 255, 0) | |
#00FFFF | rgb(0, 255, 255) | |
#FF00FF | rgb(255, 0, 255) | |
#808080 | rgb(128, 128, 128) | |
#6C5CE7 | rgb(108, 92, 231) | |
#1E3A8A | rgb(30, 58, 138) | |
#0F766E | rgb(15, 118, 110) |
Related Learning Guides
Frequently Asked Questions
What is the HEX code for rgb(255, 0, 0)?
It is #FF0000 (pure red).
Can I paste a value directly?
Yes. Paste rgb(), rgba() or plain values like 108, 92, 231, and the inputs fill in automatically.
Why do some colors not have a short HEX code?
A 3-digit code only exists when both digits of every pair are the same, like #FF8800 → #F80.
How is alpha converted to HEX?
The alpha percentage is scaled to 0–255 and written as two hex digits at the end of the code, for example 50% → 80.
Is RGB to HEX conversion exact?
Yes, for whole RGB values from 0 to 255. Alpha may be rounded to the nearest of 256 steps.