CSS z-index Property Explained
What the CSS z-index property does, with an example.
Published November 4, 2026
z-index sets the stacking order of positioned elements: higher values appear on top. It only works on elements with a position other than static (and on flex/grid items).
How it works
Stacking contexts matter: a child can never escape its parent's stacking context, so z-index: 9999 may still lose.
Opacity, transform and position with z-index create new stacking contexts.
Values and effects
z-index: -1; → behind siblings
z-index: 0; → default level
z-index: 10; → above
z-index: 1000; → modal level
Practical examples
Modal over page
.backdrop { position: fixed; inset: 0; z-index: 1000; }Sticky header
header { position: sticky; top: 0; z-index: 10; }Scale of z-index tokens
:root { --z-nav: 10; --z-modal: 100; --z-toast: 200; }Common mistakes
- Using z-index on static elements.
- Escalating to huge numbers instead of understanding stacking contexts.
- Parent transforms trapping children.
Key takeaways
- z-index in one line: z-index sets the stacking order of positioned elements: higher values appear on top.
- Inspect it live in DevTools → Styles.
- Test across browsers and screen sizes.
FAQ
Why does my z-index not work?
The element isn't positioned, or it lives in a lower stacking context.
Is z-index supported in all browsers?
Yes in all modern browsers; check caniuse.com for edge cases.