HEX to RGB: How to Convert HEX Codes to RGB (With Examples)
Learn how to convert HEX codes to RGB step by step, with worked examples for #FF5733, #2F7BFF, white and black.
You will see the same color written in two different ways on the web: as a HEX code such as #FF5733, and as an RGB value such as rgb(255, 87, 51). They describe the exact same color. Converting between them is a simple skill, and once you know the method you can do it by hand in under a minute.
This guide explains what each format is, shows the step-by-step conversion method, works through four examples with the math checked, and points out the mistakes that catch beginners most often.
What HEX and RGB Mean
A HEX code is a six-character code that starts with a hash sign. The six characters are split into three pairs. The first pair is red, the second pair is green, and the third pair is blue. Each pair uses the hexadecimal system, which counts in base 16 with the digits 0 to 9 and the letters A to F.
RGB is the same idea written in decimal numbers. It lists the red, green and blue values as numbers from 0 to 255, inside the rgb() function. So #FF5733 and rgb(255, 87, 51) are two ways of writing one color: a bright orange-red.
How to Convert HEX to RGB Step by Step
Follow these four steps for any six-digit HEX code:
- Step 1: Remove the hash sign. Turn
#FF5733intoFF5733. The hash is only a marker. It is not part of the numbers. - Step 2: Split the code into three pairs. The first two characters are red, the middle two are green, and the last two are blue. For
FF5733, the pairs are FF, 57 and 33. - Step 3: Convert each pair from hexadecimal to decimal. In hexadecimal, each character is worth 16 times the character to its right. So a pair XY equals X times 16, plus Y. The letters stand for A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
- Step 4: Write the three decimal numbers as rgb(). Put them in order: red, green, blue. That is your RGB value.
Worked Examples (Math Checked)
Here are four conversions, with every step shown so you can check the math yourself.
| HEX Code | Pairs | Decimal Math | RGB Value |
|---|---|---|---|
| #FF5733 | FF, 57, 33 | 255, 87, 51 | rgb(255, 87, 51) |
| #2F7BFF | 2F, 7B, FF | 47, 123, 255 | rgb(47, 123, 255) |
| #FFFFFF | FF, FF, FF | 255, 255, 255 | rgb(255, 255, 255) |
| #000000 | 00, 00, 00 | 0, 0, 0 | rgb(0, 0, 0) |
Example 1: #FF5733. FF means 15 times 16 plus 15, which is 240 plus 15, or 255. The pair 57 means 5 times 16 plus 7, which is 80 plus 7, or 87. The pair 33 means 3 times 16 plus 3, which is 48 plus 3, or 51. The result is rgb(255, 87, 51).
Example 2: #2F7BFF. The pair 2F means 2 times 16 plus 15, which is 32 plus 15, or 47. The pair 7B means 7 times 16 plus 11, which is 112 plus 11, or 123. FF is 255. The result is rgb(47, 123, 255), a clear blue.
Example 3: #FFFFFF. All three pairs are FF, and each FF is 255. The result is rgb(255, 255, 255), which is white. All channels at full brightness make white.
Example 4: #000000. All three pairs are 00, and each 00 is 0. The result is rgb(0, 0, 0), which is black. All channels off make black.
Using the Free HEX to RGB Converter
Manual conversion is useful to learn, but you do not need to do it by hand every time. For daily work, use the free HEX to RGB converter on Front Design Tool. Paste or type a HEX code, and it gives you the RGB value instantly, with no sign-up and no cost.
For background on the HEX format, see our guide to what a HEX color code is, or pick a color with the free online color picker.
Common Mistakes to Avoid
- Mixing up the channel order. The pairs are always red, green, blue, in that order. Swapping the first and last pairs turns a blue into a red, and the result will look completely wrong.
- Forgetting to double three-character codes. The code
#F53means#FF5533, not#F53000or any other guess. Double each character before you convert. - Reading A to F as decimal digits. The letter F is 15, not 6, and E is 14, not 5. If you treat letters as small numbers, every channel that contains a letter will come out too low.
- Leaving out the hash in code, or adding it to RGB. HEX codes in CSS start with
#, such as#FF5733. RGB values do not use a hash. They use thergb()function, such asrgb(255, 87, 51). - Assuming the result must look different. HEX and RGB describe the same color, so the converted value should look identical on screen. If it looks different, check the channel order and the letter values first.
HEX to RGB conversion is a small skill, but it removes a lot of friction from everyday design work. Learn the four steps, check your first few conversions against the free converter, and soon you will be able to read either format at a glance.