Determining a Color Attribute’s Value
Whenever you use one of the color selection attributes such as bordercolor, bgcolor, bordercolorlight, bordercolordark, and so on in an HTML tag to set an element’s color, you specify the color you want as a hexadecimal number. For example, to create a table with a light yellow background, you would set the bgcolor attribute in the table’s <table> tag as follows:
<table bgcolor="#FFFFE0">
Similarly, to draw a dark blue border around the perimeter of a table and around each of the cells within the table, you would set the bordercolor attribute in the table’s <table> tag as follows:
<table bordercolor="#00008B">
The attribute value that tells the Web browser what color to use when drawing a Web page element or painting a background color is called a hexadecimal (base 16) red-green-blue triplet. In other words, the one large hexadecimal number is actually three separate hexadecimal values (hence the term “triplet” in its name). These values tell the browser “how much” red, green, and blue to mix in order to create the color you want the browser to use when drawing the element or painting the background.
When creating a color, each of the three primary colors (red, green, blue) can have a value from 0–255 (inclusive), where “0” means none and 255 is the maximum amount. Therefore, in the second example in the current Tip in which the bordercolor attribute in the <table> tag sets the table borders to dark blue, the “#00008B” bordercolor setting tells the Web browser to create the border color by mixing 0 red with 0 green and 139 blue. (A hexadecimal value of 8B equals a decimal value of 139.) Thus, the Web browser creates the shade of dark blue you specified by mixing no red, with no green, and just over half the maximum amount of blue.
To determine the hexadecimal red-green-blue triplet for the color you want the Web browser to use, visit http://www.htmlhelp.com/cgi-bin/color.cgi, or check the font or background color menu in your favorite image editor. Most graphics programs will provide the RGB (that is, the red, green, blue) values used to create the color you select from a palette of color swatches or mix on a “custom colors” screen within the application. Or, if you use the Microsoft Office suite of programs, click the drop-down list button to the right of the Font Color button on the standard toolbar in Microsoft PowerPoint or Microsoft Word. Then, click More Colors at the bottom of the drop-down menu. The Office application, in turn, will display a Colors dialog box.
If the Custom tab’s contents are not visible, click the Custom tab on the Colors dialog box. To “mix” a custom color, click on the color you want in the color palette at the top of the Custom tab and then on the color saturation slide-bar to the right of the palette. Each time you create a color, the dialog box will show you the color in the color swatch in the lower-right corner of the dialog box and the color’s RGB value in the Red, Green, and Blue fields. If the RGB values are decimal and not hexadecimal numbers, you must convert each one to its hexadecimal equivalent. Then, combine the three hexadecimal RGB values into a single hexadecimal triplet as “#RRGGBB” (where RR, GG, and BB are the hexadecimal red, green, and blue values of the color you mixed). You can view a list of hexadecimal triplets at http://www.htmlhelp.com/cgi-bin/color.cgi.