What a hex colour code is
A hex colour is a compact way of writing three numbers (how much red, green and blue to mix) in base 16. Each channel takes two digits, so a full code has six: two for red, two for green, two for blue. Base 16 counts 0–9 and then a–f, which means two digits can express 256 different values, 0 to 255: exactly the range an RGB channel uses. That’s why #ff5733 and rgb(255, 87, 51) describe the very same orange: one writes the numbers in base 16, the other in ordinary decimal.
Converting by hand
Take #ff5733 and split it into ff, 57 and 33. For each pair, multiply the first digit by 16 and add the second, remembering that a–f stand for 10–15. So ff is 15 × 16 + 15 = 255, 57 is 5 × 16 + 7 = 87, and 33 is 3 × 16 + 3 = 51. Put them together and you have rgb(255, 87, 51). Three-digit shorthand is expanded first by doubling each digit: #f53 becomes #ff5533, then converts the same way. It only works when both digits of every pair match, which is why not every colour has a shorthand.
Transparency in hex codes
Add a fourth pair and the code carries opacity. #ff573380 is #ff5733 with an alpha of 80, and the four-digit shorthand #f538 works the same way. Alpha is stored in the same 0–255 range as the colour channels, so it converts to the 0–1 decimal CSS uses by dividing by 255. A few values are worth knowing: ff is fully solid, cc is 80%, bf is 75%, 40 is 25% and 00 is invisible. 50% sits between 7f and 80, because half of 255 isn’t a whole number: this tool reads 80 as 0.502. One warning for anyone moving between platforms: CSS puts alpha last, while Android writes it first as #AARRGGBB, so the same digits can mean different colours.
Choosing which format to use
All the outputs are the same colour; they differ in what’s convenient. rgb() and rgba() are the classic forms and work everywhere. HSL describes a colour as hue, saturation and lightness, which makes it the easiest to adjust by hand: nudging the lightness up gives a lighter shade of the same colour, something hex and RGB make awkward. The modern form, rgb(255 87 51 / 0.5), drops the commas and puts alpha after a slash. It’s the one to reach for when a colour is stored in a CSS variable, because the three numbers can live in the variable and the opacity can change wherever it’s used.
Rounding and precision
Hex and RGB are exact: whole numbers from 0 to 255. HSL isn’t, because its natural values are fractional, and the tool shows them rounded to whole numbers as they’re usually written. Converting an HSL value back to RGB can therefore land a step away from the colour you started with. For alpha, the tool shows up to three decimals, which is enough to return to the same 0–255 step every time. If you’re matching a colour exactly, copy the RGB or hex value rather than the HSL one.
Converted on your device
There’s no server behind this converter. The conversion is a few lines of arithmetic that run in your browser as you type, so nothing you enter is sent, stored or logged anywhere.