Syntax & Values

opacity: 1;      /* fully visible (default) */
opacity: 0.5;    /* 50% transparent */
opacity: 0;      /* fully invisible (still occupies space) */
opacity: 50%;    /* same as 0.5 — percentage syntax */
⚠️ Note: An element with opacity: 0 is invisible but still occupies its space in layout and still receives pointer events. Use visibility: hidden to also block events, or display: none to remove from layout entirely.

Effect on Children

opacity applies to the element and all its descendants as a group. You cannot make a child more opaque than its parent:

.parent {
  opacity: 0.5;
}
.child {
  opacity: 1; /* Still appears at 50% — can't override parent opacity */
}

If you only want a transparent background without affecting text, use rgba() instead:

/* This only makes the background transparent, not the text */
.card {
  background: rgba(99, 102, 241, 0.1);  /* ✅ children unaffected */
  /* NOT: opacity: 0.1;  ← would make all children transparent too */
}

Stacking Context

Any element with opacity less than 1 creates a new stacking context. This means:

Alternatives

GoalUse Instead
Transparent background onlybackground: rgba(0,0,0,0.5)
Transparent text onlycolor: rgba(0,0,0,0.5)
Invisible but interactiveopacity: 0 (pointer events remain)
Invisible and non-interactivevisibility: hidden
Removed from layoutdisplay: none
Animate in/outTransition opacity 0↔1 (performant)