CSS 3 Digit Hex Colors

The CSS 3-digit hex color notation is shorthand for the 6-digit hex notation.

Some six-digit hex colors can be written using a three-digit shorthand. Three-digit shorthand is where you combine the duplicate digits from each color component into one.

This results in a three digit hex number instead of six.

So instead of the syntax being like this (i.e. six-digits):

It becomes this:

Converting 6-Digits into 3-Digits

To convert a six-digit code into three, simply "dedupe" the duplicate values from each color component.

Here's an example of the same color using both the full hex notation and the shortcut version.

See how we've just deduped the duplicate characters from each color component. We've converted FF to F, CC to C, and 00 to 0.

Both of the values in this example result in the same color.

Suitable Colors

Note that you can only use the shorthand method when both values are the same for each of the RGB components.

So you couldn't turn #FC0456 into shorthand because each of the RGB components uses a different value. In this case, the red component uses FC, the green component uses 04, and the blue component uses 56. You can't dedupe those, as they are unique values.

Likewise, you can't turn #FFCC91 into shorthand either, because the green component uses different values. And you can't have a four character shorthand code. It's either three characters (for the shorthand), or six characters (for the longhand).

However, you can always round digits up or down in order to create a shorthand code. For example, #FF1493 could become something like #F19 or #F29 if you're not fussy about the precise color.

Web Page Example

Here's a working example of using three-digit hex notation to define colors for a web page. Try changing some values in the hex codes to see how it updates the color. For example, replace the F with say, 7.

Possible Values

Each character can be a hexadecimal value from 0 to F. So it can be any of the values in the "Hex..." column of the following table.

Decimal ValueHex Equivalent
00
11
22
33
44
55
66
77
88
99
10A
11B
12C
13D
14E
15F

Most people in the modern world are used to the decimal system. As shown in this table, the decimal system (which uses base 10), uses digits that go from zero to nine, then repeats by prepending a 1 to the number (resulting in 10, 11, 12, etc), then when it repeats again, it prepends a 2 (resulting in 20, 21, 23, etc), and then a 3, etc.

The hexadecimal system, on the other hand, doesn't need to repeat until it gets to F.

By the way, it's case-insensitive, so you can use uppercase or lower case letters.