HTML and CSS Reference

In-Depth Information

Specify color using hex codes

Now let's tackle those funky-looking hex codes. Here's the secret to them: each set of two

digits of a hex code just represents the red, green, and blue component of the color. So the

first two digits represent the red, the next two the green, and the last two represent the blue.

Like this:

Alw
ays start a hex code

wit
h the # sign.

#cc6600

green

Wait a sec, how is “f”

or “c” a digit? Those

are letters!

Believe it or not, they are digits, but they're

written using a notation only a computer

scientist could love.

Here's the second secret to reading hex codes: each set of two

digits represents a number from 0 to 255. (Sound familiar?)

The problem is that if we used numbers, we'd only be able to

represent up to 99 in two digits, right? Well, not wanting to be

constrained by something as simple as the digits 0-9, computer

scientists decided they could represent all 256 values with the

help of some letters too (A-F). This is the
hexadecimal
system of

numbering, or “hex” for short.

Let's take a quick look at how hex codes really work, and then

we'll show you how to get them from color charts or your photo

editing application.