Appendix D. Color Names and Values
The first thing you need to learn about color is how to specify exactly the color you want; after all, there are a lot of different reds, greens, and blues, and it is important you choose the right ones.
In XHTML there are two key ways of specifying a color:
Hex codes: A six-digit code representing the amount of red, green, and blue that make up the color, preceded by a pound or hash sign # (for example,
#333333
).Color names: A set of names that represent over 200 colors, such as
red, lightslategray
, andfuchsia
.
In CSS you can also use values to represent the red, green, and blue values that make up each color.
Using Hex Codes to Specify Colors
When you start using hexadecimal codes (or hex codes for short), they can appear a little daunting. The idea that colors are represented by a mix of numbers and letters might seem a little strange, but what follows the #
sign is actually the amount of red, green, and blue that make up the color. The format for hex codes is:
# rrggbb
The table that follows provides some examples.
Color | Hexadecimal Code |
---|---|
Black |
|
White |
|
Red |
|
Green |
|
Blue |
|
Purple |
|
As you might already know, computer monitors work in a color space known as an RGB color space. When a computer monitor is not switched on, the screen is black because it is not emitting any color. To create the image you see onscreen, each of the pixels that make up the screen emits different amounts of the colors red, green, and blue, just like ...
Get Beginning Web Programming with HTML, XHTML, and CSS, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.