Hex to RGB Color Converter (and HSL)

Convert colors between hex (#RGB, #RRGGBB, #RRGGBBAA), RGB and HSL, with CSS-ready values you can copy. Alpha transparency supported.

Three, four, six or eight hex digits (0–9, A–F), with or without the #. Four and eight digits end with an alpha (transparency) value.

Results

Hex
#FF5733
Normalized to upper case with every digit written out.
RGB
rgb(255, 87, 51)
HSL
hsl(10.6, 100%, 60%)
Hue, saturation and lightness are shown to one decimal place.

How it’s calculated

Screens mix red, green and blue light. Each channel is a number from 0 to 255 (one byte). A hex color writes the three bytes as two hexadecimal digits each: #RRGGBB. The short form #RGB doubles every digit (#F53 is #FF5533), and a fourth digit (short form) or a last pair of digits (long form) adds an alpha (opacity) value.

HSL describes the same color as a hue angle on the color wheel, a saturation and a lightness, which is easier to adjust by hand. The conversions use the algorithms in the CSS Color Module Level 4:

R, G, B = byte values ÷ 255 max = largest of R, G, B; min = smallest; d = max − min lightness L = (max + min) ÷ 2 saturation S = (max − L) ÷ min(L, 1 − L) (0 if d = 0) hue H = 60° × [ (G − B) ÷ d (+6 if G < B) | (B − R) ÷ d + 2 | (R − G) ÷ d + 4 ] for max = R | G | B HSL → RGB: f(n) = L − S × min(L, 1 − L) × max(−1, min(k − 3, 9 − k, 1)), k = (n + H ÷ 30) mod 12 R = f(0), G = f(8), B = f(4)

Example: #FF5733 has R = 255, G = 87, B = 51. Then max = 1, min = 0.2, d = 0.8, L = 0.6 and S = 0.4 ÷ 0.4 = 1. Because red is the largest channel, H = 60° × (36 ÷ 204) = 10.6°. The color is rgb(255, 87, 51) = hsl(10.6, 100%, 60%).

Frequently asked questions

How do I convert a hex color to RGB?

Split the code into three pairs and convert each pair from base 16 to a number from 0 to 255. For #FF5733: FF = 255, 57 = 87, 33 = 51, so the color is rgb(255, 87, 51).

What do the extra two digits in an 8-digit hex code mean?

They are the alpha (opacity) channel: 00 is fully transparent and FF is fully opaque. For example #FF573380 is the same orange at about 50% opacity (80 hex = 128 of 255).

Why is my HSL result not a round number?

RGB uses whole numbers from 0 to 255, so most colors land between the "tidy" HSL values. Results here show one decimal place. Going from HSL to RGB, each channel is rounded to the nearest whole number.

Is a 3-digit hex code the same as a 6-digit one?

Yes. #ABC is shorthand for #AABBCC: each digit is repeated. Only colors whose channels are repeated digits (like FF, 33, 00) can be written in the short form.

Embed this calculator

Add this free calculator to your own website. Copy the code below into your page’s HTML:

Need this calculator branded, changed or built around your own prices?See custom business solutions →

Sources

Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.

Added · Last updated · How we check our calculators

Spotted a mistake or missing option? Report a problem· Suggest a calculator