Hex

Let's take a look at hex colors.

We'll cover the following

Hex colors

Hex colors (or hexadecimal colors) are defined by specific sequences of values.

For example:

p {
  color: #00FFFF;
}

Each hex color code is a six-digit combination of letters and numbers defined by its mix of Red, Green, and Blue (RGB). The first two characters represent the red value, the next two are the green value, and the last two are the blue value. The range is from 00 to FF, where 00 doesn’t add any color to the value and FF adds the full value to the overall color.

Hex code is essentially shorthand for its RGB value!

Some examples of hex code include:

  • 000000: Black
  • FFFFFF: White
  • FF0000: Red
  • 00FF00: Green
  • 0000FF: Blue
  • FFC0CB: Pink
  • FFA500: Orange

If our pairs of RGB values are all doubles, we can abbreviate the value to a three-character shorthand. So, #FFFFFF can be defined as #FFF, as done so in the following code:

color: #FFFFFF; /* white */
color: #FFF;    /* also white! */

Example

Get hands-on with 1400+ tech skills courses.