How RGB and HEX colour codes work
Screens mix red, green and blue light. Each channel is a number from 0 (off) to 255 (full),
giving 256³ ≈ 16.7 million colours. A HEX code writes the same three numbers in hexadecimal,
two digits each: #RRGGBB. So #FFFFFF is white, #000000 is black and
#FF0000 is pure red.
| Colour | HEX | RGB |
|---|---|---|
| White | #FFFFFF | rgb(255, 255, 255) |
| Black | #000000 | rgb(0, 0, 0) |
| Red | #FF0000 | rgb(255, 0, 0) |
| Lime | #00FF00 | rgb(0, 255, 0) |
| Blue | #0000FF | rgb(0, 0, 255) |
| Yellow | #FFFF00 | rgb(255, 255, 0) |
| Orange | #FFA500 | rgb(255, 165, 0) |
| Grey | #808080 | rgb(128, 128, 128) |
When to use each format
- HEX: the most common format in CSS, design tools and brand guidelines.
- RGB / RGBA: handy when you need transparency, as in
rgba(90, 63, 224, 0.5). - HSL: the easiest format for making a colour lighter or darker by changing one number.
- CMYK: printing. The values here are a simple conversion; your printer's colour profile will vary.
Frequently asked questions
Convert each of the red, green and blue values (0–255) to a two-digit hexadecimal number and join them after a #. For example rgb(90, 63, 224) becomes 5A, 3F and E0, so #5A3FE0.
Split the six digits into three pairs and convert each pair from hexadecimal to decimal. #FF8800 is FF = 255, 88 = 136 and 00 = 0, which gives rgb(255, 136, 0). Paste any HEX code into the HEX field above to convert it.
A shorthand where each digit is doubled: #F80 means #FF8800. It only works for colours whose pairs repeat.
It measures how readable text is on a background, from 1:1 (invisible) to 21:1 (black on white). WCAG guidelines ask for at least 4.5:1 for normal text (AA) and 7:1 for the stricter AAA level.