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.

HEX

#3366ff

RGB

rgb(51, 102, 255)

HSL

hsl(225, 100%, 60%)

HSV / HSB

hsv(225, 80%, 100%)

CMYK

cmyk(80%, 60%, 0%, 0%)

RGB 0–1

0.200, 0.400, 1.000

Text contrast (WCAG)

On white — Aa4.68:1 · AA
On black — Aa4.49:1 · AA large
Advertisement

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 = 255

Python:

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

ColorHEXRGB
Black#000000rgb(0, 0, 0)
White#ffffffrgb(255, 255, 255)
Red#ff0000rgb(255, 0, 0)
Green#008000rgb(0, 128, 0)
Lime#00ff00rgb(0, 255, 0)
Blue#0000ffrgb(0, 0, 255)
Yellow#ffff00rgb(255, 255, 0)
Orange#ffa500rgb(255, 165, 0)
Purple#800080rgb(128, 0, 128)
Navy#000080rgb(0, 0, 128)
Teal#008080rgb(0, 128, 128)
Gray#808080rgb(128, 128, 128)
Silver#c0c0c0rgb(192, 192, 192)
Maroon#800000rgb(128, 0, 0)
Pink#ffc0cbrgb(255, 192, 203)
Gold#ffd700rgb(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.

Related tools