RGB to HEX Converter
Enter red, green and blue values (0–255) — or paste rgb(194, 66, 66), rgba(0, 59, 68, 1) or 32, 7, 1 — and get the hex color code.
Paste rgb(), rgba(), hsl() or “R, G, B” here.
How to convert RGB to HEX
Each RGB channel is a number from 0 to 255. In hex, the same number is written with two base-16 digits (00–FF). Convert each channel, then join them after a #.
- Divide the channel by 16. The whole-number result is the first hex digit.
- Take the remainder. That is the second hex digit. Values 10–15 become A–F.
- Repeat for green and blue, then concatenate:
#RRGGBB.
Example: rgb(194, 66, 66)
- 194 ÷ 16 = 12 remainder 2 →
C2 - 66 ÷ 16 = 4 remainder 2 →
42 - 66 ÷ 16 = 4 remainder 2 →
42
Result: #C24242. Small values need a leading zero — rgb(32, 7, 1) is #200701.
RGBA to 8-digit HEX
To keep transparency, multiply alpha (0–1) by 255, round it, and append it as a fourth pair. rgba(108, 92, 231, 0.4) → 0.4 × 255 = 102 = 66 → #6C5CE766. With alpha 1 the extra pair is FF and can be dropped: rgba(0, 59, 68, 1) = #003B44. The RGBA guide has a full alpha-to-hex table.
Examples
| RGB | HEX | |
|---|---|---|
| rgb(255, 255, 255) | #FFFFFF | white |
| rgb(0, 0, 0) | #000000 | black |
| rgb(255, 0, 0) | #FF0000 | red |
| rgb(255, 87, 51) | #FF5733 | orange-red |
| rgb(194, 66, 66) | #C24242 | brick red |
| rgb(32, 7, 1) | #200701 | near-black brown |
| rgb(0, 59, 68) | #003B44 | deep teal |
| rgb(0, 0, 247) | #0000F7 | blue |
| rgb(0, 0, 136) | #000088 | navy-like blue |
| rgb(108, 92, 231) | #6C5CE7 | violet |
| rgb(128, 128, 128) | #808080 | gray |
In code
// JavaScript
const rgbToHex = (r, g, b) =>
'#' + [r, g, b].map(v => v.toString(16).padStart(2, '0')).join('').toUpperCase();
rgbToHex(194, 66, 66); // "#C24242"
# Python
def rgb_to_hex(r, g, b):
return f"#{r:02X}{g:02X}{b:02X}"
Frequently asked questions
How do I convert RGB to HEX?
Convert each channel (0–255) to a two-digit hexadecimal number and join them after a #. Divide the value by 16: the whole-number result is the first digit and the remainder is the second (10–15 become A–F). rgb(194, 66, 66) gives C2, 42, 42, so the hex code is #C24242.
How do I convert rgba() to hex?
Convert R, G and B as usual, then multiply alpha by 255, round, and convert that to two hex digits. rgba(108, 92, 231, 0.4) → alpha 0.4 × 255 = 102 = 66, giving the 8-digit hex #6C5CE766. If alpha is 1, you can drop it: rgba(0, 59, 68, 1) is simply #003B44.
Why does single-digit RGB need a leading zero in hex?
Every channel must be exactly two hex digits. Values 0–15 convert to a single digit (0–F), so they need a leading zero: rgb(32, 7, 1) is #200701, not #2071.
Is RGB to HEX conversion exact?
Yes. Both formats store 8 bits per channel, so every rgb() value has exactly one 6-digit hex code and converting back gives the same numbers. Only alpha can lose a little precision, because 8-digit hex stores it in 256 steps.