Skip to the page
css reference · interaction & polish

CSS opacity

type
property
applies to
any element
inherits
no
common values
0 to 1 (0.5 is half transparent)

Where it goes

On the box to fade, often paired with transition: opacity 200ms. For a see-through background with solid text, use a color with alpha (rgba) on background-color instead.

Example

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.toast {
  opacity: 0;
  transition: opacity 200ms;
}
.toast.show { opacity: 1; }

Common mistakes

  • Using opacity to make a background see-through and finding the text faded too. opacity fades everything. Use rgba() on the background.
  • Hiding things with opacity: 0 and leaving them clickable. Invisible buttons still get tapped. Add visibility: hidden or pointer-events: none, or use display: none.
  • Dimming labels with opacity and failing contrast. Half-faded grey on white is often unreadable. Pick a real color that passes.

Related

Updated 24 October 2026. Practice it in the css route, or read more on MDN.