Menu

Colors in Programming, Part 2: Alpha, Opacity and Transparency
📰

Colors in Programming, Part 2: Alpha, Opacity and Transparency

DEV Community: css·Surhid Amatya·8 days ago
#fXgdq2p4
#devtocss#devto#dev#rrggbb#aarrggbb
Long article (735 words) — no AI summary yet.
Reading 0:00
15s threshold

In part 1, a color was #RRGGBB . #FF0000 is red.

But what if you want red that's only half visible? That's what alpha is for. You've probably seen codes like these:

#80FF0000 #80000000 #80FFFFFF

Enter fullscreen mode

Exit fullscreen mode

The extra two characters aren't another color. They're alpha.

What alpha does

RGB says what color it is. Alpha says how opaque it is, meaning how much of it shows over whatever is behind. It uses the same range as the other channels, 0 to 255, or 00 to FF in hex:

00 = fully transparent FF = fully opaque

Enter fullscreen mode

Exit fullscreen mode

Opacity vs transparency

These are opposites, and mixing them up causes real bugs.

100% opaque = 0% transparent 50% opaque = 50% transparent 20% opaque = 80% transparent

Enter fullscreen mode

Exit fullscreen mode

If a designer says "make it 20% transparent", that's 80% opaque.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.