z-index controls stacking order within stacking contexts. Bigger number is not global by default.
Stacking context triggers
- Positioned elements with z-index.
- Transforms, opacity < 1, filters, and some other properties.
- Root and isolation boundaries.
Pitfall
A child with huge z-index cannot escape parent stacking context if parent is below another context.
Important interview questions and answers
- Q: Why can
z-index: 9999still be hidden?
A: It may be trapped inside a lower stacking context. - Q: How to debug layering bugs?
A: Inspect stacking contexts in DevTools and simplify layering hierarchy. - Q: Team strategy for overlays?
A: Define a z-index scale/token system for modal, dropdown, tooltip tiers.
Pitfall: Check cascade order—author stylesheet loses to inline styles and !important surprises.