CSS Named Colors
CSS includes a set of named colors, so that common colors can be written and read more easily.
When using any CSS property that accepts a color value, you have the option of providing a named color. Named colors are an easy to remember set of color names that can be used as an alternative to other methods such as hex, RGB, and HSL.
Using a named color is just a matter of adding the color name to the color property in question.
Here's an example where we apply color names to three different properties:
Case-Insensitive
Named colors are case-insensitive. Therefore, the following are all valid color names, and will result in the same RGB color:
Web Page Example
Here's an example of using named colors in a basic HTML document.
Matching Named Colors with RGB
There are 147 named colors in CSS Colors Module Level 4, which is in draft status at the time of writing. The list is based on the X11 colors, which were also defined in SGL 1.0.
All color names have a corresponding RGB/hex value, but not all RGB/hex values have a corresponding color name. After all, RGB/hex provides over 16 million possible colors — slightly more than 147!
Mind you, CSS hasn't always had that many named colors. CSS started with the 16 basic color names from HTML, and then later added orange. So here are the 17 basic color names to make it in to CSS 2.1:
Color Name | Hex Code RGB |
Decimal Code RGB |
---|---|---|
Maroon | 800000 | 128,0,0 |
Red | FF0000 | 255,0,0 |
Orange | FFA500 | 255,165,0 |
Yellow | FFFF00 | 255,255,0 |
Olive | 808000 | 128,128,0 |
Green | 008000 | 0,128,0 |
Color Name | Hex Code RGB |
Decimal Code RGB |
---|---|---|
Purple | 800080 | 128,0,128 |
Fuchsia | FF00FF | 255,0,255 |
Lime | 00FF00 | 0,255,0 |
Teal | 008080 | 0,128,128 |
Aqua | 00FFFF | 0,255,255 |
Blue | 0000FF | 0,0,255 |
Color Name | Hex Code RGB |
Decimal Code RGB |
---|---|---|
Navy | 000080 | 0,0,128 |
Black | 000000 | 0,0,0 |
Gray | 808080 | 128,128,128 |
Silver | C0C0C0 | 192,192,192 |
White | FFFFFF | 255,255,255 |
Here's a full list of the CSS color names defined in CSS Color Module Level 4.
Other Color Keywords
In addition to the above named colors, you can use the transparent
keyword to set a transparent color, and the currentColor
keyword to use the current value of the color
property.