HTML Color Codes Explained: HEX, RGB, HSL & Beyond
Every CSS color format with examples, current support for wide-gamut color(), and what we found measuring the 148 named colors: only 139 distinct values, and darkgray is brighter than gray.
The Formats at a Glance
| Format | Example | Notes |
|---|---|---|
| HEX | #FF6B6B, #F66, #FF6B6B80 | 3, 4, 6 or 8 digits; the last pair is alpha |
| rgb() | rgb(255 107 107 / 50%) | space syntax; rgba() is now an alias |
| hsl() / hwb() | hsl(0 100% 71%) | hue-based, easy to edit, not perceptual |
| lab() / lch() / oklab() / oklch() | oklch(0.72 0.17 25) | perceptual; can express colors beyond sRGB |
| color() | color(display-p3 1 0.3 0.3) | any predefined space, e.g. Display P3 for wide-gamut screens |
| Named | tomato | 148 keywords, plus transparent and currentColor |
All of these describe the same thing, a color, and convert into each other; how to convert HEX and RGB by hand or in code is covered in our HEX to RGB guide. MDN's compatibility data lists color() in Chrome and Edge 111, Firefox 113 and Safari 15, so wide-gamut values are usable today with an sRGB fallback before them.
Named Colors: Measured
We read the CSS Color 4 keyword table (via the coloraide library) and computed each color's relative luminance, the brightness measure WCAG contrast uses (October 14, 2026; script in our test folder):
- There are 148 names but only 139 distinct colors: nine pairs share a value, mostly gray/grey spellings, plus aqua = cyan and fuchsia = magenta.
- The names are not a scale.
darkgray#a9a9a9 has a luminance of 0.397, brighter thangray#808080 at 0.216; onlydimgray#696969 (0.141) is darker. The names came from the X11 color list and were never designed as steps. green#008000 is the dark one (0.154); the pure screen green islime#00ff00 (0.715).- Named colors cover 0.0008% of the 16.7 million 8-bit sRGB values, so use them for prototypes and examples, and tokens with exact values in production.
Which Format to Use
- HEX for values copied from design tools and for compact tokens.
- oklch() when you build scales or adjust lightness, because equal steps look equal.
- rgb() with a slash or 8-digit HEX for transparency.
- color(display-p3 …) for vivid brand colors on wide-gamut screens, with an sRGB value declared first as the fallback.
- Custom properties (
--brand: …) so a color is defined once and themes can override it.
The Color Converter reads every format above and returns the others, gamut-mapping colors that fall outside sRGB.
Paste a HEX, RGB, or HSL value and get every format at once. Free, no signup.
⚡ Open Color Converter