HEX to RGB Converter
Paste a hex color code (with or without #) to get its RGB value, ready to copy into CSS, Android, Flutter or any design tool.
#3366ff
rgb(51, 102, 255)
hsl(225, 100%, 60%)
hsv(225, 80%, 100%)
cmyk(80%, 60%, 0%, 0%)
0.200, 0.400, 1.000
Text contrast (WCAG)
The HEX to RGB formula
A hex color #RRGGBB holds red, green and blue as two hexadecimal digits each. Each pair is a number from 00 to FF, which is 0 to 255 in decimal:
value = first digit × 16 + second digit
The hex digits A–F stand for 10–15. Worked example for #FFA500 (orange): FF = 15 × 16 + 15 = 255, A5 = 10 × 16 + 5 = 165, 00 = 0. Result: rgb(255, 165, 0).
Shorthand and 8-digit codes
CSS allows a three-digit shorthand where every digit is doubled, so #f80 means #ff8800 = rgb(255, 136, 0). Eight-digit codes such as #3366ff80 add an alpha (opacity) pair at the end; the first six digits are converted exactly as above and the last pair divided by 255 gives the opacity (80 → 128 ÷ 255 ≈ 0.5).
HEX to RGB in code
JavaScript:
const hex = "3366ff";
const [r, g, b] = [0, 2, 4].map(i => parseInt(hex.slice(i, i + 2), 16));
// r = 51, g = 102, b = 255Python:
h = "3366ff"
r, g, b = (int(h[i:i+2], 16) for i in (0, 2, 4))
# (51, 102, 255)Common hex codes and their RGB values
| Color | HEX | RGB |
|---|---|---|
| Black | #000000 | rgb(0, 0, 0) |
| White | #ffffff | rgb(255, 255, 255) |
| Red | #ff0000 | rgb(255, 0, 0) |
| Green | #008000 | rgb(0, 128, 0) |
| Lime | #00ff00 | rgb(0, 255, 0) |
| Blue | #0000ff | rgb(0, 0, 255) |
| Yellow | #ffff00 | rgb(255, 255, 0) |
| Orange | #ffa500 | rgb(255, 165, 0) |
| Purple | #800080 | rgb(128, 0, 128) |
| Navy | #000080 | rgb(0, 0, 128) |
| Teal | #008080 | rgb(0, 128, 128) |
| Gray | #808080 | rgb(128, 128, 128) |
| Silver | #c0c0c0 | rgb(192, 192, 192) |
| Maroon | #800000 | rgb(128, 0, 0) |
| Pink | #ffc0cb | rgb(255, 192, 203) |
| Gold | #ffd700 | rgb(255, 215, 0) |
Frequently asked questions
- Do I need to type the # sign?
- No. 3366ff and #3366ff both work, as do shorthand codes like fff.
- Is HEX to RGB conversion lossless?
- Yes. Both formats describe the same 256 levels per channel, so converting HEX to RGB and back always gives the original code.
- What is the RGB value of #000000 and #FFFFFF?
- #000000 is rgb(0, 0, 0), black, and #FFFFFF is rgb(255, 255, 255), white.