Skip to content

Z-Index Not Working

Quick summary

Your z-index value is not working because the element needs a position value other than static (the default).

Why this happens

  • The element has position: static (the default), which ignores z-index

  • A parent element creates a stacking context that limits the child's z-index range

  • Competing z-index values on sibling elements are not set correctly

Minimal example

✗ Broken code
.modal {
  z-index: 999;
  /* position is static by default */
}
✓ Fixed code
.modal {
  position: fixed;
  z-index: 999;
}

z-index only works on positioned elements. Adding position: fixed (or relative/absolute/sticky) makes z-index take effect.

How to diagnose

  • Check the element's position in DevTools — is it static?

  • Inspect parent elements for stacking contexts (transform, opacity, will-change)

  • Compare z-index values of sibling elements

How to fix

  • Set position: relative, absolute, fixed, or sticky on the element

  • Increase the z-index value above competing elements

  • Remove or adjust parent stacking contexts if they limit the child

How to prevent

  • Always set a position value when using z-index

  • Use a consistent z-index scale (e.g., 10, 20, 30, 100)

Related Resources

Related Glossary

Related Lessons

  • CSS

    Learn CSS positioning.

← Back to language