Color Values - HTML 4

(X)HTML defines color values in two ways:

  • By name (you choose from a limited list)
  • By number (harder to remember, but you have many more options)

Color names
The HTML specification includes 16 color names that you can use to define colors in your pages.

The Cheat Sheet bound into the front of this book has information about the 16 named colors, including names, corresponding hex codes (the six-digit hexadecimal numbers that also define the colors), and color swatches. You can safely use color names in your CSS markup and be confident that browsers will recognize them and use the correct colors in your Web pages.

This CSS style declaration says all text within <p> tags should be blue:

p {color: blue;}

If you’re looking for burnt umber, chartreuse, or salmon, you’re out of luck. A box of 64 crayons this list is not. You can, however, also find hex codes for Web-safe colors, along with color swatches, on the Cheat Sheet. These colors, though unnamed, are Web-safe because they reproduce pretty reliably on most color computer display devices and printers.

Color numbers
Color numbers allow you to use any color (even salmon) on your Web page.

1. Hexadecimal color codes
Hexadecimal notation uses six characters — a combination of numbers and letters — to define any color. If you know a color’s hexadecimal code (often called a hex code for short), you have all you need to use that color in your HTML page.

When you use hexadecimal code to define a color, you should always precede it with a pound sign (#). This CSS style declaration makes all text contained by <p> tags blue:

p {color: #0000FF;}

Unlike the familiar base 10 (decimal) system that uses 10 numerals to represent all possible numbers, the hexadecimal (base 16) system uses 16 “numerals.” If you want to know more about the hexadecimal system or want to convert numbers from decimal to hexadecimal, visit

2. RGB values
You can use two RGB values to define color. These value types aren’t as common as hexadecimal values, but they’re just as effective:

  • rgb(r,g,b): The r, g, and b are integers between 0 and 255 that represent the red, green, and blue of the color.
  • rgb(r%,g%,b%): The r%, g%, and b% represent the percentage of red, green, and blue of the color.

Every color can be defined as a mixture of red, green, and blue (RGB). You can use either an RGB value or the equivalent hex code to describe a color’s RGB value to a Web browser.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

HTML 4 Topics