HEX shorthand and transparency
HEX color codes can be as short as #fff or as long as #ffffff80. Each length has a different meaning, and once you know the rules you can read a color and its transparency straight from the code.
Structure of a 6-digit HEX
#RRGGBB writes red, green and blue as two hexadecimal digits each. Hexadecimal uses 0 to 9 and a to f to give 16 levels per digit, so two digits cover 256 levels from 00 (0) to ff (255). In #7c3aed, 7c is 124, 3a is 58 and ed is 237, so it equals rgb(124, 58, 237). If hexadecimal feels unfamiliar, just remember that each digit runs from 0 to 15, where a is 10 and f is 15. A two-digit value is the first digit times 16 plus the second, so 7c is 7×16+12=124.
00 means none of that light and ff means the maximum. So #000000 is black, #ffffff is white and #ff0000 is pure red. When all three values are equal you get gray, and #808080 is a mid gray.
3-digit shorthand #RGB
A color can be shortened to one digit per channel only when each channel’s two digits are the same character. To read shorthand, imagine each digit written twice.
- #fff becomes #ffffff (white)
- #f0a becomes #ff00aa (a vivid pink)
- #369 becomes #336699 (a calm blue)
- Cannot be shortened — #7c3aed has pairs with different characters. Only a code like #7733ee, where each pair repeats, can become #73e.
Transparency with 8 and 4 digits
Adding two more digits after the HEX gives transparency, called alpha. In #RRGGBBAA, an AA of ff is fully opaque and 00 is fully transparent. The 3-digit form also has a #RGBA version with one extra digit, and the same write-each-digit-twice rule applies, so #f008 is #ff000088, a semi-transparent red. If calculating alpha by hand is a bother, picking the nearest value from the table is enough. The difference is too small to see, so there is no need to separate 25 percent from 26 percent.
Alpha is added to the color, so what you see depends on what is behind it. The same #00000080 looks gray over white and a dark yellow over yellow.