Course contentsShow
← Web Development
Lesson 230 of 2,9824. CSS Layout FoundationsFree lesson

Stacking Contexts Without z-index

Properties that create stacking contexts automatically: opacity, transform, filter, and mix-blend-mode.

Stacking Contexts Without z-index

You'll learn: How certain CSS properties automatically create stacking contexts, even when you haven't touched z-index.

The Automatic Trigger

You've learned that z-index can create stacking contexts, but it's not the only way! Several CSS properties automatically create a new stacking context just by being applied. These properties include opacity (when less than 1), transform (any value except none), filter (any value except none), and mix-blend-mode (any value except normal).

Think of it like rooms in a house: when you add these special properties, you're essentially building a new room with its own internal layering rules. Everything inside that element gets its own mini-universe of stacking order, isolated from the outside.

Why This Matters

This automatic behavior catches many developers by surprise. You might apply opacity: 0.9 to make something slightly transparent, not realizing you've just created a stacking context. Now all the children of that element are trapped in their own layering system, unable to interact with z-index values outside their parent.

.parent {
  opacity: 0.9; /* Creates a stacking context automatically! */
}

.child {
  z-index: 9999; /* Only competes with siblings, not outside elements */
}

This is why an element with z-index: 1 outside the .parent might still appear above .child despite its massive z-index value.

Common Context Creators

  • opacity: Any value less than 1
  • transform: translate(), scale(), rotate(), etc.
  • filter: blur(), brightness(), drop-shadow(), etc.
  • mix-blend-mode: Blending effects like multiply, screen

Key Takeaway: Visual effects like opacity, transform, filter, and mix-blend-mode automatically create stacking contexts, isolating their children's layering from the rest of the page.