What is a 3-digit HEX code?
A 3-digit HEX code is a short form of a 6-digit code, written as #RGB instead of #RRGGBB. Each of its 3 digits stands for one color channel: the first is red, the second is green, and the third is blue. The code #F53 is a short way to write a red-green-blue mix.
Shorthand exists because CSS accepts it, and it saves 3 characters every time you write a color. It is the same color written shorter, not a different color system. The short form works only for colors whose 6-digit pairs are doubles, which is a small share of all colors. Most real colors, such as #3B82F6, cannot be shortened at all.
Short form — rgb(255, 85, 51).
Toggle between the short and long form: the swatch never changes, proving both codes name the same color.
The doubling rule: #RGB becomes #RRGGBB
Expand a 3-digit code by doubling each digit: #RGB becomes #RRGGBB. The code #abc becomes #aabbcc, because a becomes aa, b becomes bb, and c becomes cc. Each digit is copied once, in place, for its own channel.
The rule is one digit at a time, and the order never changes: the first digit doubles into the red pair, the second into the green pair, and the third into the blue pair. The code #F00 becomes #FF0000, which is pure red, and #0F0 becomes #00FF00, which is pure green. Doubling is the whole rule: there is no math, no rounding, and no guessing, so a short code always expands to exactly one long code.
Each digit visibly doubles into its pair, one pair at a time.
Only 4,096 colors
Shorthand can name only 4,096 colors, while the full 6-digit form can name 16,777,216. That is because shorthand has 3 digits at 16 values each, which is 16 times 16 times 16, or 4,096. Full HEX has 6 digits, so it has 4,096 times more room.
Each shorthand digit has 16 possible values, from 0 to F, so 3 digits give 4,096 combinations. Each pair in the full form has 256 values, so 3 pairs give 16,777,216 combinations. Shorthand covers about 1 in every 4,096 full colors, which is roughly 0.02 percent of them. That is why shorthand is fine for pure colors and grays, but useless for most brand colors and photos.
All 4,096 shorthand colors — one 64-by-64 grid
The full form would need 4,096 such grids to show all 16,777,216 colors.
Move the slider to 100% and back: shorthand covers about 1 in every 4,096 full colors.
When shorthand is safe
Shorthand is safe when the color you want already has doubled pairs, and when exactness does not matter. Use it for black #000, white #FFF, pure red #F00, and grays such as #888, where the short form is exact and the code is shorter.
Grays are the best case for shorthand, because a gray has equal red, green, and blue, so its 3 digits are often the same. The code #888 expands to #888888, a medium gray, and #CCC expands to #CCCCCC, a light gray. Shorthand is also safe in quick notes, sketches, and examples where a near color is good enough. It is not safe for a brand color, a color from a screenshot, or any color where the exact code matters, because the exact code probably has no short form.
#000 shortens exactly to #000000 — safe.
Tap a code: safe ones show their doubled pairs, unsafe ones have no short form.
Common mistakes
The most common mistake is thinking #abc means #abcabc, but it means #aabbcc. Each digit doubles in place, so a becomes aa, b becomes bb, and c becomes cc. Writing #abcabc is a different color, because its red pair is ab instead of aa.
A second mistake is shortening a code whose pairs are not doubles, such as #FF5733: its pairs are FF, 57, and 33, and only FF is a double, so there is no short form. A third mistake is dropping the hash sign, which makes CSS read the code as a word, not a color. A fourth mistake is writing 4 digits, such as #abcd, that is not shorthand but the 4-digit form with an alpha digit, covered in our guide to 8-digit HEX codes.
#aabbcc — right: each digit doubles in place.
Tap each expansion to see its swatch: the wrong colors are visibly different.
How to shorten a 6-digit code
A 6-digit code shortens only when each of its 3 pairs has two matching digits. The code #FF5533 shortens to #F53, because FF, 55, and 33 are all doubles. If even one pair is not a double, the code has no short form and must stay 6 digits.
Check the pairs one at a time: first pair, second pair, third pair. If all 3 are doubles, take the first digit of each pair and write them after a hash. If any pair fails, stop: a partial shortening changes the color. The code #AABBCC shortens to #ABC, but the code #AABBCD does not shorten at all, because CD is not a double. When in doubt, keep the 6-digit form: always correct, only 3 characters longer.
Worked examples
#abc expands to #aabbcc, which is rgb(170, 187, 204). The digit a doubles to aa, which is 10 × 16 + 10 = 170. The digit b doubles to bb, which is 11 × 16 + 11 = 187. The digit c doubles to cc, which is 12 × 16 + 12 = 204. It is a pale blue-gray, not the color #abcabc would give. Check it with the HEX to RGB Converter.
#F00 expands to #FF0000, which is rgb(255, 0, 0), pure red. The digit F doubles to FF, which is 255, and the two 0 digits double to 00, which is 0. This is the classic shorthand case: a pure color with two channels at zero.
#888 expands to #888888, which is rgb(136, 136, 136), a medium gray. The digit 8 doubles to 88, which is 8 × 16 + 8 = 136, for all 3 channels. Equal channels always give a gray, and this gray is just past halfway from black to white.
#FF5733 cannot be shortened. Its pairs are FF, 57, and 33. Only FF is a double, while 57 and 33 are not, so there is no 3-digit code for this color. Writing #F53 would give #FF5533, which is rgb(255, 85, 51), a slightly different orange-red.
Each pair gets a check or a cross for being a double; the short form appears only when all 3 pairs pass.