HEX to RGB Converter

Enter a hex color code to convert it to RGB and HSL, or enter RGB values to get the hex. A live swatch shows the color, and everything runs in your browser.

Enter a HEX code or RGB values and press Convert.

The conversion

A hex color packs three numbers — red, green and blue — into six hexadecimal digits, two per channel. Converting to RGB just means reading each pair as a base-16 number from 0 to 255:

#RRGGBB R = hex(RR), G = hex(GG), B = hex(BB)

Going the other way, each RGB value (0–255) becomes a two-digit hex pair, padded with a leading zero if needed. The two notations are exactly equivalent — hex is compact for stylesheets, RGB is easy to compute with.

Worked example

Converting #1D4ED8 to RGB:

Red: 1D = 1×16 + 13 = 29.
Green: 4E = 4×16 + 14 = 78.
Blue: D8 = 13×16 + 8 = 216 → rgb(29, 78, 216).

Shorthand and alpha

CSS also allows 3-digit shorthand like #1d8, which expands by doubling each digit to #11dd88. An optional fourth pair (or fourth digit) sets the alpha channel for transparency — #1d4ed880 is the same blue at ~50% opacity. This converter accepts 3- or 6-digit hex with or without the leading # and shows the equivalent RGB and HSL.

Tip: want to browse and pick a color visually first? Use the color picker.

Frequently asked questions

How do I convert a hex color to RGB?

Split the six-digit hex into three pairs (RR, GG, BB) and read each pair as a base-16 number from 0 to 255. For example #1D4ED8 becomes rgb(29, 78, 216).

What does the 3-digit hex shorthand mean?

It's a compact form where each digit is doubled. #1d8 expands to #11dd88, so the channels are 17, 221, 136. This converter handles both forms.

Can I convert RGB back to hex?

Yes. Enter the R, G and B values and the tool shows the matching hex code, padding each channel to two digits.

What about transparency (alpha)?

An optional eighth hex digit pair sets opacity, so #1d4ed880 is the same color at about 50% alpha. RGB's equivalent is the rgba() form with a fourth value from 0 to 1.

MB
Mustafa Bilgic · Editor, Calcool
Conversions use the standard sRGB hex/RGB/HSL relationships. See the MDN hex-color reference. Everything runs in your browser — nothing you enter is uploaded, logged or stored.

Related calculators