↑ ↓ to moveEnter to openEsc to close

HEX to RGB converter

Paste a HEX code and get the RGB values plus the arithmetic that produced them. Short codes and alpha digits are handled, and bulk mode converts a pasted list.

  • RGB
  • RGBA
  • CSS 4
  • 0–1

The math for your code

 
Bulk mode: convert a list
 

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

ChannelPairDigitsCalculationResult
RedD9D = 13, 9 = 913 × 16 + 9217
Green484 = 4, 8 = 84 × 16 + 872
Blue1C1 = 1, C = 121 × 16 + 1228

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 pairDecimalOpacity
FF2551 (opaque)
E62300.902
CC2040.8
B31790.702
991530.6
801280.502
661020.4
4D770.302
33510.2
1A260.102
0000 (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) or rgb(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. #D9481C and #9D481C are 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.