How the conversion works
A six-digit HEX code is three two-digit numbers written in base 16, one each for red, green and blue. Base 16 uses the digits 0 to 9 and then A (10), B (11), C (12), D (13), E (14) and F (15). Each pair can therefore range from 00 (0) to FF (255), the same 0 to 255 range as an RGB channel.
To turn a pair into a decimal number, multiply the first digit by 16 and add the second:
value = first digit × 16 + second digit
Worked example: #D9481C
| Channel | Pair | Digits | Calculation | Result |
|---|---|---|---|---|
| Red | D9 | D = 13, 9 = 9 | 13 × 16 + 9 | 217 |
| Green | 48 | 4 = 4, 8 = 8 | 4 × 16 + 8 | 72 |
| Blue | 1C | 1 = 1, C = 12 | 1 × 16 + 12 | 28 |
So #D9481C is rgb(217, 72, 28). The tool writes these steps out for whatever code you type, so you can check homework or explain the result to someone else.
Short codes: 3 and 4 digits
CSS allows a three-digit shorthand where each digit is doubled. #ABC means #AABBCC, which is rgb(170, 187, 204). Only colors whose pairs are doubled digits can be shortened, so #D9481C has no short form, while #FF6600 does (#F60).
A four-digit code like #F608 adds a doubled alpha digit: #FF660088.
Alpha: 8-digit HEX to RGBA
The fourth pair in an eight-digit code is alpha (opacity), on the same 0 to 255 scale. Divide by 255 to get the 0 to 1 value CSS uses in rgba().
#0F766E80 breaks down as red 15, green 118, blue 110 and alpha 80 = 128. Since 128 ÷ 255 = 0.502, the result is rgba(15, 118, 110, 0.502). Handy reference points:
| Alpha pair | Decimal | Opacity |
|---|---|---|
| FF | 255 | 1 (opaque) |
| E6 | 230 | 0.902 |
| CC | 204 | 0.8 |
| B3 | 179 | 0.702 |
| 99 | 153 | 0.6 |
| 80 | 128 | 0.502 |
| 66 | 102 | 0.4 |
| 4D | 77 | 0.302 |
| 33 | 51 | 0.2 |
| 1A | 26 | 0.102 |
| 00 | 0 | 0 (invisible) |
The four outputs
- RGB in the classic comma syntax,
rgb(217, 72, 28), which every browser and most design tools accept. - RGBA with the alpha value, even when it is 1.
- CSS 4 in the modern space-separated syntax,
rgb(217 72 28)orrgb(15 118 110 / 50.2%). All current browsers support it. - 0–1 channels divided by 255, for shader code, Swift's
UIColor, Unity or any API that wants floats.
Bulk mode
Open Bulk mode, paste one code per line, and each line is converted. Invalid lines are marked rather than skipped, so the output always lines up with your input. It is useful for turning a brand palette or a design-token export into RGB for an Android colors.xml or a spreadsheet.
Common mistakes
- Swapped digits.
#D9481Cand#9D481Care very different colors. When converting by hand, read the pairs left to right. - Confusing O and 0. HEX only contains the digit zero. If a code will not convert, look for a letter O or a lowercase L.
- Wrong alpha position. CSS puts alpha last (
#RRGGBBAA), but Android and some older Microsoft formats put it first (#AARRGGBB). If a color looks wildly wrong, that is the likely cause.
To go the other way, use RGB to HEX. To see the same color in every format at once, including HSL and OKLCH, use the color converter. If you are working with plain numbers rather than colors, the hex to decimal converter handles any length.
FAQ
Is HEX the same as RGB?
Yes, in the sense that both describe the same sRGB color. HEX is just a compact base-16 spelling of the three RGB numbers.
Why is FF equal to 255?
F is 15, so FF is 15 × 16 + 15 = 255. Two hex digits hold exactly 256 values, 0 to 255, which fits one byte.
Can a HEX code have letters beyond F?
No. Valid digits are 0 to 9 and A to F. A code containing G or higher is not a HEX color.
Does uppercase or lowercase matter?
No. #d9481c and #D9481C convert to the same RGB values.