0.5.1 Hexadecimal Web Colors

Hexadecimal Can Represent Color

You have already used hexadecimal as a compact way to represent binary values.

Web pages provide a familiar place where hexadecimal appears visually: color values.

A hexadecimal web color commonly uses six hexadecimal digits after a # symbol.

For example:

Plain text
#3366CC

The six digits are grouped into three pairs:

Plain text
33 66 CC

Those pairs represent the red, green, and blue parts of the color.

RGB Means Red, Green, and Blue

Screens create many colors by combining different amounts of:

A six-digit hexadecimal color can be read as:

Plain text
#RRGGBB

where:

Each pair ranges from hexadecimal:

Plain text
00

through:

Plain text
FF

That corresponds to decimal values from 0 through 255.

00 Means None of That Color Component

Consider:

Plain text
#000000

The groups are:

Plain text
Red   = 00
Green = 00
Blue  = 00

With all three components at zero, the result is black.

Now consider:

Plain text
#FFFFFF

Each component is at its maximum hexadecimal value:

Plain text
FF

The result is white.

Pure Red, Green, and Blue

A strong red value can be represented as:

Plain text
#FF0000

That means:

Plain text
Red   = FF
Green = 00
Blue  = 00

A strong green:

Plain text
#00FF00

A strong blue:

Plain text
#0000FF

The position of the hexadecimal pair matters.

The same symbols in a different position describe a different mixture.

Mixed Values Produce New Colors

Consider:

Plain text
#FFFF00

The color contains maximum red and maximum green, with no blue.

That produces yellow.

Another example:

Plain text
#00FFFF

contains green and blue at maximum values.

That produces cyan.

The goal is not to memorize a huge color chart.

The important idea is that one written hexadecimal value encodes three numeric color components.

Connect Each Pair to Binary

Because one hexadecimal digit corresponds to four bits, one two-digit color component corresponds to eight bits.

For example:

Plain text
FF

maps to:

Plain text
11111111

and:

Plain text
00

maps to:

Plain text
00000000

So:

Plain text
#FF0000

can be understood as three groups of eight bits:

Plain text
11111111 00000000 00000000

The web color is another real example of hexadecimal acting as a shorter human-readable representation of binary-oriented information.

The # Is Part of the Web Color Notation

When a color appears in HTML or CSS, you may see:

Plain text
#3366CC

The # helps indicate that the following characters form a hexadecimal color value.

The hexadecimal digits themselves are:

Plain text
3366CC

CSS Can Apply the Color

A small CSS example is:

CSS
h1 {
    color: #3366CC;
}

Read it as:

Display h1 heading text using the color represented by hexadecimal #3366CC.

You do not need to master CSS yet.

For now, notice the connection:

hexadecimal representation → digital color → visible result on a webpage

Uppercase and Lowercase Hex Digits Represent the Same Values

These two values represent the same color:

Plain text
#3366CC

and:

Plain text
#3366cc

Hexadecimal digits A through F are not changed in value by letter case.

A project may still use one style consistently for readability.

Short Hexadecimal Color Notation Exists

You may encounter a three-digit form such as:

Plain text
#36C

In CSS, this expands each digit:

Plain text
#36C

to:

Plain text
#3366CC

The six-digit form makes the red, green, and blue pairs easier to see while you are learning the representation.

Color Is a Good Example of Representation

The visible color is not stored on the page as a painted square.

It is represented by data.

For example:

Plain text
#3366CC

is text that represents three numeric color components.

The browser interprets those values and displays the resulting color.

That follows an idea you have seen throughout FIT:

digital systems use representations that software interprets to produce meaning or behavior.