liveBook · Manning

Opacity

As explained in Web Design Playground, Second Edition

The CSS opacity property specifies the degree to which an element and its contents are transparent.

Opacity controls whether something is visible through its transparency. Think of it as a dimmer switch for an element: `opacity: 0` hides it completely, while `opacity: 1` makes it appear. Handy when you want a caption or image to wait quietly until someone interacts with it. section 15.8 section 20.5

A common move is to hide an absolutely positioned layer, then reveal it with `:hover`. The layer stays in place over the image; only its visibility changes. No browser magic, just a carefully placed invisible thing becoming visible. section 15.8 section 20.5

Reveal a photo caption

Place a caption over a thumbnail, give it a translucent background, and hide the caption first: `.image-caption {` ` position: absolute;` ` left: 0; top: 0;` ` width: 300px; height: 200px;` ` background-color: rgba(32, 32, 32, 0.75);` ` opacity: 0;` `}` Then reveal it when the pointer reaches the caption: `.image-caption:hover {` ` opacity: 1;` `}` The `rgba()` background remains slightly see-through, while `opacity` decides whether the caption itself is shown. section 15.8 section 17.4

Fade in an image overlay

For before-and-after images, stack the after image above the before image. Start the overlay at `opacity: 0`, set `transition: opacity 1.5s ease`, and change its opacity to `1` on hover. The transition turns an abrupt appearance into a gradual fade. section 20.5

Use the gallery result to see the intended interaction: a hidden caption appears over a thumbnail when hovered. section 15.8

How Web Design Playground, Second Edition covers it

How deep it goes
Demonstrates `0` and `1` through positioned gallery layers, with transitions shown for overlays.
Examples
Shows a hoverable photo caption and fading before-and-after portfolio images.
What you can do after
Apply it with CSS to reveal overlaid captions or images on hover.
How it connects
Connects opacity with `:hover`, absolute positioning, `z-index`, transitions, and RGBA transparency.

Also explained in

Compare how 3 books explain opacity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.