CSS opacity Property Explained

What the CSS opacity property does, with an example.

Published November 5, 2026

opacity sets how transparent an element and all its children are, from 0 (invisible) to 1 (fully opaque).

How it works

It affects the whole element including text and children. To make only the background transparent use rgba() or hsla().

Elements with opacity < 1 create a stacking context.

Values and effects

opacity: 1; → fully visible
opacity: 0.5; → half transparent
opacity: 0; → invisible but still takes space and clicks

Practical examples

Fade on hover

.img { opacity: .8; transition: opacity .2s; }
.img:hover { opacity: 1; }

Transparent background only

.overlay { background: rgba(0,0,0,.5); }

Disabled look

button:disabled { opacity: .5; cursor: not-allowed; }

Common mistakes

  • Using opacity when only the background should be transparent.
  • Expecting opacity: 0 to remove clicks.
  • Animating opacity on huge layers without will-change consideration.

Key takeaways

  • opacity in one line: opacity sets how transparent an element and all its children are, from 0 (invisible) to 1 (fully opaque).
  • Inspect it live in DevTools → Styles.
  • Test across browsers and screen sizes.

FAQ

opacity vs visibility?

opacity: 0 still occupies space and receives events; visibility: hidden does not receive events but keeps space.

Is opacity supported in all browsers?

Yes in all modern browsers; check caniuse.com for edge cases.

More CSS articles