🌐 English

Home › Guides

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.

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.

Common alpha values

Multiply the percentage by 255 and convert to hexadecimal. The frequently used values are worth memorizing.

Using it in practice

Transparency is useful for shadows, overlays and hover effects. For example, laying #00000066 over a photo puts a 40 percent black on it. But a transparent color changes contrast with its background, so when you apply alpha to text, check contrast using the color that actually appears over the real background.

Enter a HEX code in the color converter to see the matching RGB and HSL values, which helps when an alpha code is confusing and you want to split it into parts. Most modern environments understand the 8-digit form, but if you must support very old ones, the rgba() form is the safer choice.

Common mistakes

Here are the usual errors when handling HEX codes by hand. If a color looks wrong, suspect these first.