What a hex colour actually encodes
A six-digit hex colour is three bytes written back to back, one byte per channel, in the order
red, green, blue. Each byte is written as two hexadecimal digits rather than a decimal number
because two hex digits map onto a byte exactly: the range 00–ff covers 0–255 with nothing
left over and nothing missing. RGB is the same three numbers in decimal, which is why converting
hex to RGB is not really a colour operation at all — it is a base conversion, digit pair by digit
pair.
Reading the pairs by hand
Take #ff6347. Split it into ff, 63 and 47. Each hex digit is worth a power of 16, so a
pair reads as (first digit × 16) + second digit. For ff that is (15 × 16) + 15 = 255. For
63 it is (6 × 16) + 3 = 99, and for 47 it is (4 × 16) + 7 = 71. Put the three together and
you get rgb(255, 99, 71) — a warm, coral red.
The same steps on #1e90ff give 1e = 30, 90 = 144, ff = 255, so rgb(30, 144, 255), a
saturated blue. Notice the pattern: ff is always 255 and 00 is always 0, because f is the
largest single hex digit (15) and two of them is the largest possible byte.
Shorthand and alpha
CSS allows a 3-digit shorthand when every pair would repeat a digit. #333 expands to #333333,
which is rgb(51, 51, 51) — a neutral dark grey. #08f expands to #0088ff, which is
rgb(0, 136, 255). The rule is mechanical: each digit is written twice, so #08f can only ever
stand for one specific colour, never an approximation of it.
An 8-digit hex code adds a fourth pair for alpha. #ff634780 is the tomato red from above with
80 appended — 80 in hex is 128 in decimal, and 128 out of 255 is just over half, so the
browser renders it at roughly 50% opacity: rgba(255, 99, 71, 0.5). A plain 6-digit code carries
no alpha pair and is always fully opaque.
Hex, RGB and HSL side by side
All three describe the same colour space; they just make different things easy to read.
| Format | Looks like | Easiest to read off |
|---|---|---|
| Hex | #ff6347 | A short string to paste into CSS or a design tool |
| RGB | rgb(255, 99, 71) | The raw channel intensities, 0–255 each |
| HSL | hsl(9, 100%, 64%) | Hue, and how light or saturated the colour is |
When you actually need RGB
Hex is what you paste; RGB is what code often wants to compute with. A canvas drawing API, a shader uniform, or a colour-blending function typically takes three numbers, not a six-character string, so converting is the first step before the colour is usable in a program rather than a stylesheet. Design tools also tend to display RGB in an inspector panel even when the swatch was picked as hex, so this conversion is one you will do in both directions constantly once you start working across CSS and code.