Stacking Context
Last updated
Was this helpful?
Last updated
Was this helpful?
Josh โฉ โญ๏ธโญ๏ธโญ๏ธ
Not all stacking contexts use positioned layout. ๐ See:
Not all positioned elements create a stacking context. (ไพๅฆ๏ผๅชๆ display: relative ๆฒๆ z-index)
:root (<html>) - top-level stacking context
child inside a display: flex | grid , with z-index โ auto ( โญ๏ธ even static children โ๏ธ )
position: relative | absolute, with z-index โ auto
position: fixed | sticky ( โญ๏ธ no z-index needed โ๏ธ)
opacity < 1
mix-blend-mode โ normal
transform | filter | clip-path | perspective | mask (value โ none)
will-change: opacity | transform
contain: layout | paint
isolation: isolate - explicitly creates a context
๐ See: ๐ MDN โฉ
All the elements within a stacking context are stacked in this order (from back to front):
the root element of the stacking context
positioned elements with a negative z-index (along with their children)
non-positioned (static) elements
positioned elements with a z-index of auto (and their children)
positioned elements with a positive z-index (and their children)
root element's background and borders
Descendant static blocks (in order of appearance in the HTML)
floating blocks
Descendant static inline elements
Descendant positioned elements (in order of appearance in the HTML)
Within containers, when the property alters rendering from the "order of appearance in the HTML" , it similarly affects the order for stacking contextโ๏ธ
MDN โฉ Stacking Context โฉ
When the property is not specified on any element, elements are stacked in the following order (from bottom to top):
MDN โฉ