colorbeginner

Opacity

The transparency level of an element, from 0 (invisible) to 1 (fully opaque).

Plain English

Opacity controls how see-through something is. A disabled button at 50% opacity communicates "this exists but you cannot use it right now." An overlay at 60% opacity dims the background while letting the user still sense what is behind it. In CSS, there are two ways to add transparency: the opacity property (affects the whole element including text) and rgba/hsla colour values (only affects the fill colour, not the element content).

Technical

The opacity property affects the entire element and all its descendants — including text. To make only the background transparent while keeping text fully opaque, use background-color with an alpha channel instead (e.g. rgba(0,0,0,0.5) or hsl(0 0% 0% / 0.5)). Elements with opacity < 1 create a new stacking context. Will-change: opacity enables GPU compositing for smooth transitions. opacity: 0 is not the same as visibility: hidden — opacity: 0 elements still intercept pointer events.

Live Demo

10%
20%
30%
40%
60%
70%
80%
100%

Opacity communicates hierarchy — lower opacity = secondary content.

Usage

✓ Good usage

Use opacity: 0.5 + pointer-events: none on disabled buttons — the reduced opacity signals unavailability without requiring a different colour.

✗ Bad usage

Using opacity: 0 to visually hide content — the element still occupies space, blocks clicks, and is accessible to screen readers, creating invisible traps.

Common mistakes

AI Prompt Example

Copy this into Claude, Cursor, Bolt, or v0.

Use opacity: 0.5 for disabled interactive elements. Use rgba(0,0,0,0.6) for modal backdrops. Use transparent border colours (hsl(210 40% 90% / 0.8)) for subtle dividers rather than solid grey.