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:
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