Overflow, Stacking Contexts, and Layering
Diagnose clipping, scroll containers, containing blocks, and z-index interactions without arbitrary numbers.
Overflow describes what happens when content exceeds a box; stacking contexts determine how painted boxes are ordered as groups. Clipping, scrolling, and layering interact with sticky positioning, focus rings, menus, and dialogs. Diagnose the owning box before adding overflow hidden or a larger z-index.
See the core pattern
Read this rule set from the outside in. Identify the inputs, the decision or transformation, and the result before changing it.
.table-region { overflow-x: auto; } .card { position: relative; isolation: isolate; } .badge { position: absolute; z-index: 1; }Working rules
- Find the element creating overflow before hiding it
- Keep focus rings and popovers outside accidental clipping
- Reason about stacking contexts as groups
A common mistake
z-index 999999 cannot escape an ancestor stacking context or clipping boundary.
Guided practice
Create a horizontally scrollable data region and a locally layered card badge without causing page-level scrolling.
- Copy the example into the editable notebook below.
- Change one thing at a time and keep the program or rule valid.