A Complete Guide to Web Design

(やまだぃちぅ) #1
76 Chapter 5 – HTML Overview

Specifying Color in HTML


Web Design in a Nutshell, eMatter Edition

Specifying Color by RGB Values


The most common and precise way to specify a color in HTML is by its numerical
RGB values. For an explanation of RGB color, see “Color on the Web” in
Chapter 3,Web Design Principles for Print Designers.
Once you’ve identified the red, green, and blue values of your chosen color, you’ll
need to translate them to theirhexadecimalequivalents in order to enter them into
the HTML color tag. These values are written in HTML with the following syntax:
"#RRGGBB"
whereRRstands for the hexadecimal red value,GGstands for the hexadecimal
green value, andBBstands for the hexadecimal blue value. Using these values,
you can specify any color from the “true color” space (millions of colors).
Let’s look at an example to put this in context. To set the background color of a
document to dark olive green, the complete HTML tag would look like this:
<BODY BGCOLOR="#556B2F">

The hexadecimal system

The hexadecimal numbering system is base-16 (as opposed to base-10 for decimal
numbers). It uses the following 16 characters:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
A through F represent the decimal numbers 10 through 15.

Converting decimal to hexadecimal

You can calculate hex values by dividing your number by 16 to get the first digit,
then using the remainder for the second digit. For example, dividing the decimal
number 203 by 16 yields 12 with a remainder of 11. The hexadecimal value of 12
is C; the hex value of 11 is B. Therefore, the hexadecimal equivalent of 203 is CB.
Fortunately, there are more simple methods for converting numbers to
hexadecimal:


  • Use the conversion chart in Table 5-1, which translates decimal values from 0
    to 255.

  • Use a hexadecimal calculator. On the Macintosh, you can download a copy of
    a utility called Calculator II (ftp://ftp.amug.org/pub/mirrors/info-mac/sci/calc/
    calculator-ii-15.hqx). Windows users will find a hexadecimal calculator in the
    “Scientific” view of the Windows’ standard calculator.

  • Use online resources. There are several resources online for calculating hexa-
    decimal equivalents. Some allow you to enter all three values for red, green,

Free download pdf