XML technologies / HTML & XHTML / Color specifications
(Excerpt from "HTML & XHTML ─ kurz & gut" by Jennifer Niederst Robbins)
Colors belong to the presentation of (X)HTML and should therefore be defined with Cascading Style Sheets rather than HTML attributes. The following material is included only for completeness.
In both (X)HTML and CSS colors can be specified using numeric values or standardized color names.
RGB values
The most common and precise way to define a color is by its numeric RGB (red, green, blue) values. Image editors such as Adobe Photoshop can determine a color’s RGB values on a scale from 0 to 255. For example:
Red: 212 Green: 232 Blue: 119
To use these numbers as attribute values, convert them to hexadecimal, base 16. In this example, the preceding values have been replaced by their hexadecimal equivalents:
Red: D4 Green: E8 Blue: 77
In (X)HTML, these values form a six-character sequence preceded by a # symbol:
#D4E877
The general syntax is:
#RRGGBB
RR represents red, GG represents green and BB represents blue, all in hexadecimal notation.
Adobe Photoshop conveniently displays hexadecimal values automatically at the bottom of the color picker next to the # symbol. The value can be copied directly from the picker into a stylesheet or HTML document.
If your image editor does not display hexadecimal colors, many converters are available online. Search for “RGB to Hex” or use one of the many web-based color pickers.
Standardized color names
Colors can also be specified by predefined names. The syntax is straightforward:
<body link="navy">
HTML 4.01 and XHTML 1.0 provide 16 valid color names, although many browsers support the full CSS3 set. Here are the names and corresponding hexadecimal values:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
These color names can also be used in stylesheets. The CSS 2.1 specification also lists the color orange (#FFA500). It therefore officially supports 17 colors. CSS 3 defines 140 standard color names already supported by many browsers. Using them in (X)HTML documents can, however, prevent those documents from validating.
Copyright © 2010 O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from "HTML & XHTML ─ kurz & gut" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de