All guides

How to Convert a HEX Color to RGB

What a hex code actually stores, how to turn it into RGB values, and when RGB is the format you want.

4 min read

Open the tool HEX to RGB Converter

A hex color code like #7c3aed is RGB written in a shorter form. To convert it, split the six digits into three pairs and read each pair as a number from 0 to 255. So #7c3aed is rgb(124, 58, 237).

If you want the answer without doing the math, paste your hex into the HEX to RGB converter and copy the RGB values straight out.

What the digits in a hex code mean

A full hex color has six digits after the hash, grouped into three pairs:

  • The first pair is red
  • The second pair is green
  • The third pair is blue

Each pair is a base-16 (hexadecimal) number. Base 16 uses the digits 0 to 9 and then the letters a to f, where a is 10 and f is 15. Two hex digits cover every value from 00 (which is 0) to ff (which is 255).

So in #7c3aed:

  • 7c is red, which works out to 124
  • 3a is green, which works out to 58
  • ed is blue, which works out to 237

That gives rgb(124, 58, 237).

How to do the conversion by hand

For one pair of digits, multiply the first digit by 16 and add the second.

Take 7c. The 7 is worth 7, and c is worth 12. So 7 × 16 + 12 = 124. Repeat for the other two pairs and you have your RGB triplet.

Short hex codes use one digit per channel. #fff is the same as #ffffff, because each digit is doubled before the conversion. So #f00 expands to #ff0000, which is rgb(255, 0, 0).

When you need RGB instead of hex

Both formats describe the same colors, so the choice is about context.

You usually reach for RGB when you need an alpha channel through rgba(), when you are working in a language or canvas API that expects separate numeric channels, or when you want to tweak one channel at a time with code. Hex stays popular in CSS and design files because it is compact and easy to paste.

The HEX to RGB converter shows the matching HSL, HSV and CMYK values too, so you can grab whatever your project needs from one place. If you have RGB and want to go the other way, the RGB to HEX converter handles that.

Frequently asked questions

What is the RGB value of
Black. Every channel is zero, so
What is the RGB value of
White. Every channel is at its maximum, so
Does the hash symbol matter?
The leading hash is just notation.