HTML and CSS Reference
In-Depth Information
FiGure 7-4
cHoosinG TeXT coLor
HTML5 provides a wide range — a full palette, if you will — of color options for text. When
assigning colors for text, it is always important to keep readability uppermost in mind. For content
to be easily readable there must be a high contrast between the background color and the text. The
CSS color property sets the color of the text, as in this example:
h1, h2 { color: maroon; }
You can specify a color value in four different ways, three of which are supported by a full slate of
browser versions. The four value methods are:
Names:
CSS2 and the upcoming CSS3 both support 16 different color names: aqua, black,
blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yel-
low. Browsers often support many other named color values, but may differ on the actual
color represented.
Hexadecimal:
A hexadecimal color is a number in base 16 that represents the red, green, and
blue (RGB) values. Hexadecimal color values start with a pound sign, like #ffffff (white)
or #000000 (black). CSS supports long notation that uses six digits where two digits repre-
sent a hexadecimal number from 0 to 255 as well as short notation with three digits. The
short notation can be used only when each of the two digits in a hexadecimal pair are the
same. In other words, #fff is the same as #ffffff .
RGB:
Two flavors of RGB notation are available: numeric and percentage. Numeric values
must be between 0 and 255, as with this example — rgb(255, 0, 0) — which is dis-
played as a pure red. To set the same color with the percentage notation, the value would be
rgb(100%, 0, 0) .
Search WWH ::




Custom Search