Z-Index and Stacking
Z-Index Support
z-index is parsed and stored per element. Paint order is influenced by z-index values:
.modal { position: absolute; z-index: 100; }
.tooltip { position: relative; z-index: 50; }
Paint Order Layers
Siblings are sorted into three layers for paint order:
- Negative layer — items with
z-index < 0 - Auto layer — non-positioned items and items with
z-index: auto - Non-negative layer — items with
z-index >= 0
Within each layer, items are sorted by their integer z-index value. Source order is preserved for equal z-index values.
Positioning Requirement
z-index only applies to positioned elements (position: relative | absolute | fixed). Static elements are always in the auto layer.
Current Limitations
- No independent stacking contexts — cross-branch ordering is still tree DFS. A deeply nested
z-index: 999paints behind a shallowz-index: 1in a different subtree. - Sibling sort works correctly; full stacking context isolation is the next step.
opacity < 1,transform, and other stacking-context triggers don't create new stacking contexts.
Paint Walk Behavior
The paint walk visits:
- Element's own background and borders
- Negative z-index children
- Auto z-index children (in-flow + non-negative)
- Non-negative z-index children
- Element's text and foreground content
This matches the CSS 2.1 Appendix E painting order within a single stacking context.