CSSHard
What is a stacking context, and why can z-index: 9999 still be covered?
By FrontendPro Editorial Team Updated 8/14/2026
#css#z-index#stacking
Answer
z-index only compares elements inside the same stacking context. If an ancestor creates a new one, its descendants can never rise above elements outside it - no matter the value.
Things that create a stacking context:
- non-
staticpositionplus a non-autoz-index opacity < 1,transform,filter,backdrop-filter,will-change,mix-blend-mode,isolation: isolateposition: fixed/sticky, flex/grid children withz-index
css
.modal-root { isolation: isolate; } /* isolate deliberately instead of escalating */
The durable fix: portal overlays to the DOM root rather than bumping z-index.
