Advertisement

HEX to RGB converter

Type a hex colour code with or without the leading number sign. Shorthand codes such as F80 are expanded, and the red, green and blue values are read from the six-digit form.

Calculator

Expanded hex code
#FFA500
CSS rgb() colour
rgb(255, 165, 0)
Red (0 to 255)
255
Green (0 to 255)
165
Blue (0 to 255)
0

Advertisement

How this calculator works

A hex colour code writes an sRGB colour as three pairs of hexadecimal digits. The first pair is red, the second green and the third blue, and each pair runs from 00 for no light to FF for full intensity. The three-digit shorthand works by doubling each digit, so F80 is the same colour as FF8800. A leading number sign is customary in CSS but is optional when the code is entered here. This page expands the code and gives the decimal channel values that JavaScript and many graphics tools expect.

Formula

Each pair of hex digits is a base-16 number from 00 to FF, which equals 0 to 255 in decimal. Shorthand ABC expands to AABBCC by repeating each digit. Example: FF is 15 x 16 + 15 = 255, A5 is 10 x 16 + 5 = 165, and 00 is 0.

Worked example

FFA500 is rgb(255, 165, 0). FF is 255, A5 is 165 and 00 is 0. The shorthand F80 expands to FF8800, which is rgb(255, 136, 0). 008000 is rgb(0, 128, 0), a medium green.

Advertisement

Frequently asked questions

Why does the code need six digits?

One pair of digits encodes each of the three colour channels, so three channels need six digits. The three-digit shorthand only works when every channel repeats its first digit.

Is the alpha channel converted?

No. This page reads the six-digit RGB form. Eight-digit hex codes add a transparency pair that is not part of the red, green and blue values.

Are these colours in the sRGB space?

Yes. Hex codes on the web are interpreted as sRGB by default. A hex code does not carry an ICC profile, so the same numbers can look different on a monitor that has not been calibrated to sRGB.

Sources

Advertisement