Performance: Stacking context
MEDIUM IMPACT
Stacking context affects how elements are layered visually and can impact paint and composite performance during rendering.
/* CSS */ .element { position: relative; z-index: 1; /* No opacity or transform here */ }
/* CSS */ .element { position: relative; z-index: 1; opacity: 0.99; transform: translateZ(0); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Many stacking contexts (opacity, transform) | No extra DOM nodes | 0 | High paint and composite cost due to multiple layers | [X] Bad |
| Minimal stacking contexts (only needed z-index) | No extra DOM nodes | 0 | Lower paint and composite cost with fewer layers | [OK] Good |