O'Reilly logo

Beginning Web Programming with HTML, XHTML, and CSS, Second Edition by Jon Duckett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix D. Color Names and Values

The first thing you need to learn about color is how to specify exactly the color you want; after all, there are a lot of different reds, greens, and blues, and it is important you choose the right ones.

In XHTML there are two key ways of specifying a color:

  • Hex codes: A six-digit code representing the amount of red, green, and blue that make up the color, preceded by a pound or hash sign # (for example, #333333).

  • Color names: A set of names that represent over 200 colors, such as red, lightslategray, and fuchsia.

In CSS you can also use values to represent the red, green, and blue values that make up each color.

Using Hex Codes to Specify Colors

When you start using hexadecimal codes (or hex codes for short), they can appear a little daunting. The idea that colors are represented by a mix of numbers and letters might seem a little strange, but what follows the # sign is actually the amount of red, green, and blue that make up the color. The format for hex codes is:

# rrggbb

The table that follows provides some examples.

Color

Hexadecimal Code

Black

#000000

White

#FFFFFF

Red

#FF0000

Green

#008000

Blue

#0000FF

Purple

#800080

As you might already know, computer monitors work in a color space known as an RGB color space. When a computer monitor is not switched on, the screen is black because it is not emitting any color. To create the image you see onscreen, each of the pixels that make up the screen emits different amounts of the colors red, green, and blue, just like ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required