For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
0
Sponsor

Stacking

The z-index property manages overlapping layers. Learn how CSS isolate prevents child elements from bleeding into global page layers and how to follow a strict z-index ladder.

Most layout order on a web page is naturally resolved by standard DOM tree order without needing manual z-index numbers. The z-index property is specifically for elements that physically overlap. When used, the essential architectural question is: which container owns that layer overlap?


1. Escaping the Container: Stacking Context Isolation

When an element inside Card A (such as an absolute notification badge) hangs over its container edge, it often unexpectedly covers neighboring Card B.

  • ❌ The Error: Assuming position: relative isolates child z-indices. In CSS specifications, a positioned element with z-index: auto does not establish a new stacking context. A child with z-10 escapes to compete in the root page's stacking order, improperly floating over adjacent siblings.
  • ✅ The Fix: Add isolate (isolation: isolate) to the parent container. This explicitly bounds all child z-indices inside the parent, letting sibling cards stack naturally according to standard DOM flow.
WrongNo isolation
Card A3
Card B
Rightisolate
Card A3
Card B
import { DesignCase } from "@/components/design-case";
import { cn } from "@/lib/utils";

2. The Standard z-index Scale Ladder

Never invent arbitrary numbers like z-[9999]. Confine all application layering to a standard ladder:

Layer LevelUtility ClassIntended Purpose
Below Flow-z-10Subtle background accents, grid patterns
Default Flowz-auto / z-0Standard page content, text, media
Local Stackingz-10Overlapping badges, local tooltips inside an isolate container
Local Stickyz-20Sticky table headers, local canvas drag handles
Fixed Navigationz-30Persistent sticky topbars, floating bottom action bars
Overlays & Backdropsz-40Backdrop scrims, modal dimmers
Portals & Dialogsz-50Modals, full sheets, global toasts, popovers

Portals vs. High z-indices

Application code should never need to exceed z-50. Modals, dropdown menus, sheets, and tooltips should be mounted into a root portal. Because portals mount at the end of the <body> element, natural DOM ordering handles top-level layering cleanly without numeric arms races.