Dustin Johnson ← Design Primitives
Design Primitive Reference · Part I · October 2026

Elevation & Depth

Surfaces, shadow, and the stack. The z-axis treated as a statement of state: what is above what, what can be touched right now, and what will go away. Five levels and the rules for who gets which.

I. Why Depth Is a Primitive

A shadow is a claim that one surface is in front of another. Depth is a primitive because that claim tells the user what is temporary, what is on top, and where their attention belongs, and a shadow that makes the claim falsely is a bug, not a style.

Start with the failure, because it is the common one. Here is a sample-tracking screen from an invented water-quality lab: a top bar, a batch header with three actions, a grid of sample cards, an inspector panel, an open overflow menu on the first card, and a toast confirming the last sample logged. Every shadow on it was added by someone with a reason: the bar "needed to feel sticky," the buttons "looked flat," the cards "needed to pop," the inspector "needed separation." Look at it before turning the inventory on.

SamplesBatchesSamplesReportsMKS1
Batches / Lake Arden intakeBatch QA-2291
FilterExportNew sampleS2
AR-114Inlet north4.2NTULogged 08:12
Open sampleDuplicateMove to batch…Archive sampleS3
AR-115Inlet south3.8NTULogged 08:20S4
AR-116Weir pool6.1NTULogged 08:41S3
AR-117Spillway2.9NTULogged 09:03
AR-118Pump house5.4NTULogged 09:15
AR-119Outfall7.0NTULogged 09:32
Sample AR-120 logged UndoS5
6 distinct shadows · 4 surfaces raised that are part of the page · 1 menu trapped under its neighbour As found · Every shadow added for a local reason · Wrong The open menu has the same shadow as the cards, so it doesn't read as above them, and the next card paints over it. The toast, the one thing that really is on top, has to shout to be seen.

Three things are wrong, and none of them is the amount of shadow. The shadows say nothing true. The cards and the open menu wear the same shadow (S3), so the menu, which really is floating above the grid, makes the same claim as the cards, which are not. There is no scale. Six shadows on one screen, each a different offset, blur, and alpha, written by hand in six components. And the order is broken. The menu is clipped by the card next to it, because the card's hover animation created a stacking context the menu can't escape (section VII). Section XI audits this screen and fixes it with two shadows.

The reason depth deserves a chapter is that the eye reads it before anything else. A shadow under a surface is the visual system's oldest cue for "this is in front," and in an interface "in front" means three things at once: it covers something (so the thing under it is temporarily unavailable), it is temporary (it arrived and will leave), and it has attention (it is what the user is dealing with now). A menu, a dialog, and a toast are all true on those three counts. A card in a grid is false on all three, which is why a shadowed card grid reads as noise: twelve surfaces each claiming to be the thing on top.

The industry has swung across this twice. Skeuomorphic interfaces put depth on everything. Flat design removed it from everything, including the places it was doing work, and produced menus that couldn't be told apart from the page beneath them. The convergence since, visible in Material 3, Atlassian, and Fluent 2, is the position this chapter takes: a few named levels, shadow reserved for surfaces that are actually above the page, and everything that is part of the page drawn flat. The button chapter reached the same place for buttons in Button Taxonomy §II: depth deployed sparingly and on purpose, not as decoration.

Shadow on everything · Wrong

The menu and the cards make the same claim. Nothing is above anything, so nothing is.

Shadow on nothing · Wrong

The flat overcorrection. The open menu reads as a third card that landed on the other two.

Shadow where something is above · Right

Cards are bordered and flat; the menu, the only temporary surface, is the only shadow.

The boundary with neighbouring chapters, stated once. Spacing & Density decides how far apart surfaces are and Grid & Layout decides where they sit; this chapter decides which of them is in front. Border & Radius (a planned Foundations chapter) owns border weight and corner radius; this chapter owns which separation method means "above." Overlays: Modal & Drawer and Overlays: Popover & Tooltip own focus trapping, dismissal, positioning, and sizing; this chapter owns the level each one sits at. Color owns the gray ramps; this chapter takes two of them, one per mode, and assigns them to levels.

A shadow is a sentence: this is in front, it will go away, deal with it now. Write it only where all three are true.

II. The Three Ways to Separate Surfaces

Separate surfaces that share a plane with a hairline or a tonal step, and reserve shadow for the one thing neither of those can say: this surface is above the others. There are only three ways to tell the eye that two surfaces are different, and they form a ladder of how much they claim.

1 · Hairline · Adjacent regions, one plane · Right
2 · Tonal step · A region with another role · Right
3 · Shadow · A different plane · Right
Shadowed sidebar · Claims it floats · Wrong
Rule + tone + shadow on one card · Wrong
Top row: one rung each, used for the job it says. Bottom row: the shadowed sidebar looks like a drawer that will slide away; the card wearing all three looks heavy and still says nothing the border didn't.

A hairline says "these are two regions of the same surface." It is the cheapest claim and the right one for the frame's regions (sidebar against main, an inspector against the content beside it), for table rows, and for cards in a grid. A tonal step says "this region has a different role." A sidebar a shade darker than the main canvas, a toolbar band, a code block, an input well: all on the same plane, but not the same kind of surface. Dark mode does most of its work this way (section VI). A shadow says "this is not part of the page." It is the only one of the three that implies a z-position, and with it, coverage, impermanence, and attention.

That gives the rule for choosing. Ask whether the surface would move if the page scrolled under it, or leave if the user pressed Escape. If neither, it is on the page, and it gets a hairline or a tone. If either, it is above the page, and it gets a shadow. The sidebar in the bottom-left frame fails that test, and the shadow makes a false promise: users read it as something that will slide shut. It is the most common misuse of shadow in application frames, and it usually comes from wanting more separation than a hairline gives; the fix for that is a tonal step, not a z-position.

MethodClaimsUse forNot for
HairlineTwo regions, one planeFrame regions, table rows, cards in a grid, list dividers, the sticky header at rest.Anything floating; a hairline alone on a menu makes it a third card.
Tonal stepSame plane, different roleSidebar or rail backgrounds, toolbars, wells and code blocks (stepped down), every level in dark mode (stepped up).Signalling interactivity; a tinted card is not a button.
ShadowAbove the planeMenus, popovers, listboxes, drawers, dialogs, toasts, drag ghosts. The sticky header only while content scrolls under it.Cards, panels, sidebars, inspectors, table rows, anything that is part of the page.

Combining them is allowed in one direction only. A raised surface may carry a hairline as well as its shadow: on a white menu over a white card, the shadow gives height but the edge is soft, and a 1px border at low alpha (--el-edge in this chapter) draws it crisply. That border is the menu's edge, the shadow is its height, and each does one job. What fails is the bottom-right card: a flat surface wearing a border, a tint, and a shadow at once, each added because the others "weren't enough." When a surface needs three cues to stand apart, the problem is usually that everything around it is wearing two.

Hairline, tone, shadow: each rung claims more than the one below. Use the lowest rung that tells the truth.

III. The Anatomy of a Shadow

A believable shadow is two shadows: a tight one that draws the edge and a wide, faint one that says how high, both in a tinted dark of the surface underneath rather than black. Every box-shadow layer has the same four parameters, and the figure labels them on a single layer before the variants show why one layer is never enough.

One layer · box-shadow: 0 16px 40px −8px rgb(46 40 30 / .32) The shadow is a copy of the box's shape, moved by the offset, grown or shrunk by the spread, softened by the blur, and painted in the color. The blur is centered on the copy's edge: half of it falls inside, half outside.

Offset says where the light is. A y-offset with no x-offset puts the light overhead and slightly in front of the user, which is the convention every major system uses and the one to keep: a shadow pushed sideways reads as a decision about the room's lighting that the rest of the interface doesn't share. The size of the offset is the strongest single cue to height. Blur says how far the surface is from what it's casting onto: a surface touching the page casts a hard shadow, one hovering above it casts a soft one. Blur and offset should grow together. Spread grows or shrinks the copy before it's blurred. A negative spread tucks a wide shadow under the box, so it falls below the surface rather than haloing out on every side, and it is the parameter most hand-written shadows forget. Color and alpha say how much light the surface blocks. Real shadows are darker versions of the surface they land on, so on warm paper the shadow is a warm dark; pure black at the same alpha reads as gray dirt rather than shade.

Two Layers, Each With One Job

A real object under a real light casts two shadows at once: a sharp, dark one right at the contact edge, where almost no light reaches, and a wide, faint one from the general light in the room. Material calls these the key and ambient shadows, and Fluent 2 builds every elevation from exactly that pair. In CSS it is two comma-separated layers. The key layer is tight: offset 1 to 3px, blur 2 to 8px, alpha around .10. It draws the edge, so the surface looks like it has a bottom. The ambient layer is wide: offset and blur that grow with the level, a negative spread, alpha .15 to .30. It says how high. A single layer can only do one of the two jobs, which is why single-layer shadows fail in one of two recognisable ways.

hard
One hard layer · Pasted on · Wrong
cloud
One soft layer · No edge, no bottom · Wrong
pair
Key + ambient · Level 3 · Right
Same height intended · the hard layer looks like a sticker, the cloud like a blur on the page
black
rgb(0 0 0 / .22)
rgb(0 0 0) · Gray on warm paper · Avoid
tinted
rgb(46 40 30 / .22)
rgb(46 40 30) · Shade of the paper · Right
Exaggerated to alpha .42 · the flat swatch under each card is the shadow color at .22 over the paper: black turns the warm paper gray, the tint only darkens it · at production alphas it's the difference between "dirty" and "deep"
4px
Blur 4 · Offset 12 · Too sharp for the height · Wrong
28px
Blur 28 · Offset 12 · About 2 × offset · Right
80px
Blur 80 · Offset 12 · A smudge · Wrong
Blur between 2× and 3× the offset reads as one object at one height

The proportion in the last row is the one to keep: for the ambient layer, blur is two to three times the offset, and the spread is about minus a quarter of the blur. Less blur than that and the shadow is too sharp for the distance the offset claims, so the surface looks like it's sitting on a hard, dark slab. More and it turns into a smudge with no discernible source. The playground below draws the ambient layer with the sliders, adds the key layer under it, and writes the CSS.

box-shadow: 0 2px 6px rgb(46 40 30 / .10), 0 18px 44px -8px rgb(46 40 30 / .24);
Ambient layer on the sliders · Key layer fixed · Starts at level 3 Turn the key layer off and the box loses its bottom edge. Push blur below twice the offset and it lands on a slab.
One layer draws an edge or a height, never both. The key layer says the surface has a bottom; the ambient layer says how far above the page that bottom is.

IV. The Elevation Scale

Use five levels, numbered 0 to 4 and named for what they mean: flat, raised, floating, overlay, top. Each level binds one shadow pair, one surface color per mode, and one band of the z-index scale, so that choosing a level for a component is the only depth decision anyone makes.

0FlatPart of the page
none
1RaisedIn front, for now
1 / 2 · 1 / 4
2FloatingAnchored, brief
1 / 3 · 8 / 20
3OverlayCovers, takes focus
2 / 6 · 18 / 44
4TopSurvives overlays
3 / 8 · 28 / 64
All five levels on one background · Captions give key and ambient as offset / blur Each level should read as obviously higher than its neighbour. If two read the same, the scale has a level too many.

0 · Flat: the canvas, cards, panels, the sidebar, tables. 1 · Raised: the sticky header while content scrolls under it, a slider's thumb, a switch's knob, the selected segment. 2 · Floating: menus, popovers, listboxes, date pickers, tooltips. 3 · Overlay: drawers, dialogs, bottom sheets, with a scrim when modal. 4 · Top: toasts and the drag ghost. Section V gives the full roster, at rest and while active.

LevelMeansShadow · key, ambientz-layerSurface · light / dark
0 · flatPart of the pagenonebase 0#fff on #f6f5f2 / #1a1a1a on #121212
1 · raisedOn the page, in front of it for now0 1px 2px .12
0 1px 4px .06
sticky 100#fff / #212121
2 · floatingAnchored to the page, temporary0 1px 3px .10
0 8px 20px −4px .16
popover 1000
tooltip 1400
#fff / #282828
3 · overlayCovers the page, takes focus0 2px 6px .10
0 18px 44px −8px .24
drawer 1100
modal 1200
#fff / #2f2f2f
4 · topUnanchored, survives overlays0 3px 8px .12
0 28px 64px −12px .30
toast 1300#fff / #363636

The shadows climb on every parameter at once: the key layer's offset goes 1, 1, 2, 3 and the ambient layer's offset 1, 8, 18, 28, with blur at roughly two and a half times the offset and a spread that tucks it further under each step. The alphas climb too, gently, because a higher surface blocks more of the room's light. In light mode every level's surface is the same white: height is the shadow's job, and only the shadow's. In dark mode the surface does the work instead (section VI).

/* The scale. Components choose a level; nothing else in the codebase writes a box-shadow. */ :root { --shadow-tint: 46 40 30; /* the paper's own dark, not black */ --elevation-0: none; --elevation-1: 0 1px 2px rgb(var(--shadow-tint) / .12), 0 1px 4px rgb(var(--shadow-tint) / .06); --elevation-2: 0 1px 3px rgb(var(--shadow-tint) / .10), 0 8px 20px -4px rgb(var(--shadow-tint) / .16); --elevation-3: 0 2px 6px rgb(var(--shadow-tint) / .10), 0 18px 44px -8px rgb(var(--shadow-tint) / .24); --elevation-4: 0 3px 8px rgb(var(--shadow-tint) / .12), 0 28px 64px -12px rgb(var(--shadow-tint) / .30); --edge: rgb(var(--shadow-tint) / .10); /* hairline on levels 2–4 */ --surface-canvas: #f6f5f2; --surface-0: #fff; --surface-1: #fff; --surface-2: #fff; --surface-3: #fff; --surface-4: #fff; --surface-sunken: #ecebe6; /* wells, tracks, code (§X) */ } /* Components consume a level, never a raw shadow. */ .menu, .popover, .listbox { background: var(--surface-2); box-shadow: var(--elevation-2); border: 1px solid var(--edge); } .dialog, .drawer { background: var(--surface-3); box-shadow: var(--elevation-3); } .toast { box-shadow: var(--elevation-4); }

Why Five

Five is the number of distinct things depth has to say in an application, and each level answers a different question: is it part of the page; is it part of the page but in front for now; is it attached to something on the page; does it cover the page; must it survive things that cover the page. A sixth level would have to answer a sixth question, and in practice it gets used for "this one should look a bit more important," which is the decorative use the scale exists to stop. Fewer than five and two of those questions share an answer: most often popovers and dialogs share a shadow, and a menu opened inside a dialog can no longer be seen to sit above it.

Real systems land in the same range. Material 3 collapsed Material 2's two dozen dp values into six levels (0 to 5) and uses the top two mostly for hover and drag states of the levels below. Atlassian names four surfaces, sunken, default, raised, and overlay, which is this scale with a well added below and the top two merged. Carbon separates nested surfaces almost entirely with alternating layer tones and keeps shadow for floating things, which is the hairline-and-tone rung of section II made into policy. shadcn/ui pairs a 1px border with a medium shadow on its popovers and menus and a larger one on its dialog, the edge-plus-height combination this chapter recommends. None of these systems uses more than six, and every one of them reserves the largest shadows for surfaces that cover the page.

Two Scales, Bound Together

The shadow says how high a surface looks; the z-index makes it true. They are two scales because order needs more distinctions than appearance does: a drawer and a dialog look the same height, but if both are open the dialog must win. So the z-index scale has eight named layers (section VII) and the shadow scale has five levels, and every layer maps to exactly one level. The one deliberate exception is the tooltip: it is small and anchored, so it takes level 2's shadow, but it must never be covered, so it takes the highest layer. Everywhere else, a component that looks higher is higher.

Name the levels for what they mean, not for how they look. A team that argues about "shadow-md" is choosing a look; a team that says "it's floating" has already chosen.

V. Resting vs Raised

A card in a grid is part of the page, so it rests flat or bordered at level 0 and never wears a shadow. Elevation at rest belongs only to surfaces that are not part of the page: menus, popovers, dialogs, drawers, toasts, and the thing being dragged. Everything else earns elevation only while something is happening to it, and gives it back when that stops.

ComponentAt restWhile something happens
Card in a grid0 · hairline1 on hover only if the whole card is one link
Panel, sidebar, inspector0 · hairline or toneStays 0. A sidebar that slides over content on a narrow screen is a drawer (3).
Table row0 · dividerStays 0; hover is a tint, selection a tint plus a mark
Sticky header0 · hairline1 while content scrolls under it
Slider thumb, switch knob, selected segment11. The moving part of a control is the one place level 1 lives at rest.
Menu, popover, listbox, tooltip2 while openDoes not exist when closed
Drawer, dialog, bottom sheet3 while open, with scrimDoes not exist when closed
Toast4 while visibleLeaves on its own
Dragged itemIts own resting level4 while dragged, leaving a slot behind

The test from section II applies without exception. A card in a grid doesn't move when the page scrolls and doesn't leave on Escape, so it is part of the page, and a shadow on it is a false claim of the kind section I's screen made twelve times over. The usual argument for shadowed cards is that they need separation from the canvas. They do, and that is the hairline's job or the tone's (a white card on a canvas one step darker). The usual argument for shadowed panels is that the screen "looks flat." It is supposed to: a flat page is what makes the one raised thing on it legible.

Buttons are a component decision rather than a surface decision, and Button Taxonomy §II made it: flat by default, a slight lift as a deliberate stylistic choice. If a system gives its buttons a lift, it is level 1 and no more, the same as a slider thumb: a control's moving part, never a surface.

Hover Elevation

Lifting on hover is honest when the lift predicts what a click will do: the whole card is one target, or the thing can be picked up. It is noise everywhere else. A card that is one big link lifts from 0 to 1 on hover, because the lift says "this entire surface is the button," which is true. In a list of such cards the lift is withdrawn all the same: a grid of surfaces that each rise under the pointer flickers as the pointer crosses it, so Cards I §V marks liveness there with a stroke or a tint, and the lift stays for a card that stands alone. A card that contains a checkbox, a menu button, and a link should not lift, because the lift promises one target and the card has three. A table row should never lift: rows are slices of one surface, and a lifted row breaks the table into pieces. Rows take a tint.

Weir pool compositeBatch QA-2288 · 12 samples · Opened Oct 9Include in report
Card with three controls, lifts · Wrong
SampleResultUnit
AR-114 Inlet north4.2NTU
AR-115 Inlet south3.8NTU
AR-116 Weir pool6.1NTU
Row lifts to level 2 · Wrong
SampleResultUnit
AR-114 Inlet north4.2NTU
AR-115 Inlet south3.8NTU
AR-116 Weir pool6.1NTU
Row takes a tint · Right
Hover each one, or force the state with the toggle. The lifted row tears the table; the lifted card with controls invites a click on its blank middle that does nothing.

Keep the lift small and fast. Level 0 to level 1 plus a 1px rise is enough; jumping a hovered card to level 3 makes it look like it is about to become a dialog. The duration and easing belong to Motion & Easing, but the rule is that the lift arrives quickly and leaves at the same speed, so it tracks the pointer rather than performing for it. And because hover doesn't exist on touch, nothing may depend on it: the card must already look like a link at rest, through its chevron and its title, before the lift confirms it.

Dragging

The dragged item is the clearest case of honest elevation, and it goes to the top: level 4, with the slot it came from left visible. The item is above everything for as long as the pointer holds it, it will be put down somewhere, and nothing else should be competing for attention. The slot matters as much as the ghost: it shows where the item will return if the drag is cancelled, and it keeps the list from closing up and jumping under the pointer.

Awaiting review · 4
AR-121Culvert east
AR-124Boathouse pier
AR-125North shoal
AR-122Reed bed transect
Ghost at level 4 · Slot kept · Right
Awaiting review · 4
AR-121Culvert east
AR-124Boathouse pier
AR-125North shoal
AR-122Reed bed transect
Translucent, flat, list closed up · Wrong
On the right the dragged item could be a fifth card that overlaps the others by accident; nothing says it is in the hand.
The page is flat so that the things above it can be seen to be above it. Every shadow at rest on a page surface spends that contrast and buys nothing.

VI. Light & Dark Mode Depth

Light mode says "higher" with a shadow; dark mode says it with a lighter surface and a faint top edge, and keeps the shadow only to darken the gap beneath. The reason is physical: a shadow is a region darker than its surroundings, and on a surface that is already nearly black there is almost no darker left. The same five levels, rendered with shadows alone on a dark canvas, collapse into one.

0Flat#fff#1a1a1a
1Raised#fff#212121
2Floating#fff#282828
3Overlay#fff#2f2f2f
4Top#fff#363636
Light · Same white surface at every level · The shadow carries height · Right Dark · Surface lightens one step per level · Top edge brightens · Shadow darkens the gap · Right Dark · Shadows only, every surface #1a1a1a · Wrong Turn dark mode on, then turn the tonal lift off: the same shadows that separate five levels on paper separate almost nothing on a #121212 canvas. The surface colors printed on each tile are the dark ramp.

The dark ramp steps the surface up about 3% in lightness per level, from #1a1a1a at level 0 to #363636 at level 4, on a canvas of #121212. It is the scheme Material's dark theme made famous with white overlays at rising opacity, and the one Apple's HIG encodes as separate base and elevated background colors, so that a sheet presented over a dark screen is visibly lighter than the screen. The two cues that make it work are the ones a light-mode shadow gets for free. The tonal step gives each level a distinct surface. The edge, a hairline of white at 6 to 10% with the top side a little brighter, draws the boundary that a light-mode key shadow would have drawn, as if the surface caught light from above. The shadow stays, in black at higher alpha, and it does a smaller job: it darkens the canvas just outside the surface so the lighter surface reads lighter still.

Dark · Menu with shadow only · Wrong

The light-mode recipe, ported. The menu is the same gray as the card under it, and its shadow is lost in the dark.

Dark · Level 2 surface + edge · Right

Two steps lighter than the card, a brighter top edge, and the shadow underneath. The menu reads as above at a glance.

LevelLight · surface, shadowDark · surfaceDark · edge (sides / top)Dark · shadow
canvas#f6f5f2#121212——
0 · flat#fff · hairline #e2e0da#1a1a1a6% / 6%none
1 · raised#fff · elevation-1#2121217% / 10%key only, black .5
2 · floating#fff · elevation-2#2828288% / 12%pair, black .5 / .6
3 · overlay#fff · elevation-3#2f2f2f9% / 14%pair, black .5 / .7
4 · top#fff · elevation-4#36363610% / 16%pair, black .5 / .75

Three consequences follow. The surface tokens are per mode, and components never pick colors. A menu asks for --surface-2 and --elevation-2; the mode decides whether that means white with a shadow or #282828 with an edge. This is the same parallel-palette argument Button Taxonomy III §G1 made for button colors: dark mode is a second ramp, not an inversion of the first. Never glow. A white or light shadow on a dark surface looks like a neon outline, not height; the edge hairline is the dark-mode replacement for the key shadow, and it is one pixel. Tonal lift is not hierarchy. A lighter surface in dark mode means "higher," so a dark-mode card that is lighter than its neighbours to look "important" is making the same false claim as a shadowed card in light mode.

Light mode has spare darkness to spend on shadows. Dark mode doesn't, so it spends light instead: each level a step brighter, each edge catching a little of it.

VII. The Stacking Order

z-index is a token scale of eight named layers, set once for the product; a raw number in a component is a bug waiting for the next overlay. The shadow scale makes a surface look higher. The z-index scale is what makes it actually paint on top, and unlike the shadow, it fails silently: the menu renders, it just renders underneath something.

The stack, side view · Highest first · Each layer drawn at its level's shadow · Gap left between page and overlays

The order is the order of what must win. The page is at the bottom. Sticky headers sit above it, and rails above them, so a rail that expands on hover covers the header too. Menus and popovers come next, above everything that is part of the page. Drawers sit above popovers, so a drawer opening closes over any menu that was open, and dialogs above drawers, so a confirmation raised from a drawer appears on top of it, with the scrim just under the dialog. Toasts sit above dialogs because a toast confirming the dialog's action must be visible while the dialog closes. Tooltips are last, because a tooltip on a button inside any of the above must never be covered by the thing it describes.

:root { --z-base: 0; /* level 0 */ --z-sticky: 100; /* level 0 at rest, 1 while scrolled under */ --z-rail: 200; /* level 0 docked, 2 while expanded over content */ --z-popover: 1000; /* level 2: menu, popover, listbox, date picker */ --z-drawer: 1100; /* level 3 */ --z-scrim: 1190; --z-modal: 1200; /* level 3 */ --z-toast: 1300; /* level 4, also the drag ghost */ --z-tooltip: 1400; /* level 2 shadow, highest layer */ }

The gaps are deliberate. The jump from 200 to 1000 separates things that are part of the page from things that are above it, so a page component that needs a local order (a badge over an avatar, a sticky table header inside a scrolling panel) can use 1 to 99 inside its own container without ever approaching an overlay. The steps of 100 leave room to insert a layer later without renumbering. Bootstrap has shipped a named scale of this shape for years, dropdowns at 1000 and tooltips near the top; the specific numbers matter much less than having names and forbidding everything else.

The Stacking-Context Trap

The most common z-index bug has nothing to do with the numbers. A z-index only competes within its stacking context, and many properties quietly create one: transform, opacity below 1, filter, backdrop-filter, will-change, isolation: isolate, contain: paint, and any positioned element with a z-index of its own. A menu with z-index: 9999 inside a card that has a hover transform is 9999 inside that card and nothing outside it; the next card, painted later, covers it. This is what happened to the menu in section I.

AR-114
Open sampleDuplicateMove to batch…Archive sample
AR-115
card: transform · menu: z-index 9999 Trapped in the card's context · Wrong

The transform was added for a hover animation. It made each card a stacking context, so the menu can't rise above its card's sibling.

AR-114
Open sampleDuplicateMove to batch…Archive sample
AR-115
menu: --z-popover · rendered at the root Out of the card, on the popover layer · Right

The menu is rendered outside the card (a portal, or the top layer) and takes its layer from the scale, so no card's styling can trap it.

The durable fix is structural: anything at level 2 or above is rendered outside the component that opened it, at the root of the document, so that no ancestor's transform, opacity, or overflow can trap or clip it. Every mature component library does this with a portal. The platform now does it natively: an element opened with <dialog>.showModal() or the popover attribute goes into the browser's top layer, above every z-index on the page, stacked in the order things were opened. Where the top layer is available, use it for levels 2 to 4 and keep the z-index scale for the layers that are part of the page (sticky, rail) and as the fallback. Where it isn't, portal to the root and use the tokens. Either way, the rule for code review is the same: a z-index in a component that isn't a token is a defect, and a z-index larger than the scale's top is two defects.

A z-index competes only inside its stacking context. Render overlays at the root, give them a named layer, and the numbers stop mattering.

VIII. Overlays & the Scrim

A scrim is required exactly when the page underneath stops responding: a modal dialog always gets one, a drawer gets one when it is modal, and a menu, popover, or tooltip never does. The scrim is not decoration and not a dimmer for drama. It is the visible half of a state change whose invisible half is that clicks on the page no longer reach it, and showing one without the other is a lie in either direction.

Archive AR-114?It moves to the batch archive and can be restored for 30 days.
CancelArchive
Dialog · Level 3 · Scrim 40% · Right
Archive AR-114?It moves to the batch archive and can be restored for 30 days.
CancelArchive
Modal dialog, no scrim · Page looks live, isn't · Wrong
Site ▾
Inlet northInlet southWeir poolOutfall
Menu · Level 2 · No scrim · Right
Site ▾
Inlet northInlet southWeir poolOutfall
Menu with a scrim · A dialog's weight for a choice · Wrong

A modal without a scrim looks like a popover, so the user clicks the page behind it, and nothing happens. A menu with a scrim looks like a dialog, so a lightweight choice suddenly feels like a decision, and a click outside it, which should simply close it, feels like it might cancel something. The pairing is fixed: levels 2 and 4 never have a scrim; level 3 has one whenever it is modal. A non-modal drawer, such as an inspector that slides in while the page stays usable, has no scrim, and it should then not cover the content the user is working with.

The Scrim's Alpha

A scrim should dim the page enough that it unmistakably can't be used, and not so much that the user loses track of what they were doing. In light mode that is about 40% of the shadow tint, the same warm dark the shadows use, so the page looks shaded rather than grayed. In dark mode it is about 60% black, since the page is already dark and needs more to recede. Lighter and the page looks live; darker and the dialog floats in a void with no context, which matters most when the dialog is asking about something on the page.

Archive AR-114?
12% · Page still looks live · Wrong
Archive AR-114?
40% tint · Receded, still legible · Right
Archive AR-114?
82% · Context gone · Wrong
Archive AR-114?
Blur 4px · Pays to hide context · Avoid

Blur is a scrim with a texture, and behind a dialog it is the wrong texture. It costs a full-screen filter on every frame the dialog animates, and it removes the one thing a scrim is careful to keep: a legible page, so the user can see which sample they are archiving. Blur has no better home elsewhere: a translucent bar with content scrolling under it pays the same filter on every frame to show a smear of what the user is about to scroll to anyway, and Part II measures what it costs the bar's own text. Behind overlays, a flat scrim at the right alpha does the job better.

Overlays Inside Overlays

Overlays open from inside overlays all the time: a select inside a dialog, a date picker inside a drawer, a confirmation raised by a dialog's action. The scale resolves every one of them with one rule: a child overlay keeps its own level's shadow and stacks directly above its parent, in the order opened. The listbox inside a dialog is still a level-2 surface with a level-2 shadow, because it is still anchored and temporary; it paints above the dialog because it was opened from it. The top layer does this by itself. With z-index tokens, it means the child renders at the root and takes its parent's layer plus one step, never its own level's layer, which would put it under the dialog.

Move AR-114Destination batchQA-2291 · Lake Arden▴NoteOptional
CancelMove
QA-2288 · Weir poolQA-2291 · Lake ArdenQA-2294 · Culvert surveyQA-2297 · North shoalQA-2302 · Reed bed
Listbox above its dialog · Level 2 shadow · Unclipped · Right
Move AR-114Destination batchQA-2291 · Lake Arden▴NoteOptional
QA-2288 · Weir poolQA-2291 · Lake ArdenQA-2294 · Culvert surveyQA-2297 · North shoalQA-2302 · Reed bed
Listbox inside the dialog's box · Clipped at its edge · Wrong
Edit AR-114SiteInlet northDepth1.5 m
CancelSave changes
Discard unsaved changes?Your edits to AR-114 will be lost.
Keep editingDiscard
Confirmation over a dialog · Second scrim · The one allowed nesting
The clipped listbox is a dialog whose body scrolls with overflow: hidden, holding a listbox rendered inside it. The fix isn't a bigger dialog; it's rendering the listbox outside.

Dialogs over dialogs are allowed exactly once, for a confirmation: closing a dialog with unsaved edits, or confirming an irreversible action that the dialog led to. The scrim moves up rather than doubling: the first dialog's scrim clears and the confirmation's scrim dims the first dialog and the page together, so the first visibly recedes and the page is never dimmed twice (Overlays: Modal & Drawer §XI measures why). The confirmation is always smaller than its parent. A second full dialog over a first is a sign the flow should have been a page or a stepped dialog. Positioning and collision handling for the listbox are covered in Select §VIII.

The boundary, stated once: the Overlays chapters (Modal & Drawer, Popover & Tooltip) own how overlays behave: focus trapping and return, dismissal on Escape and outside click, sizing in large viewports, positioning and collision. This chapter owns where they sit: the level, the layer, the scrim, and the order when one opens from another.

A scrim means the page has stopped listening. Show it exactly when that's true, at an alpha that still lets the user see what they were working on.

IX. Focus, Attention & the Z-Axis

The highest surface that takes input is the one that has focus, and when two surfaces are raised at once, the screen is asking two questions of a user who can answer only one. Depth is how the screen shows where attention belongs. The keyboard focus, the visual height, and the scrim all have to agree on a single surface.

New · Pin your sitesPin the sites you sample most and they'll appear first.
Export batch QA-229124 samples, all analyses.FormatCSV · one row per sample▾
CancelExport
Coach mark stays above the scrim · Two raised surfaces · Wrong Closed · A coach mark is the one raised thing · Fine
New · Pin your sitesPin the sites you sample most and they'll appear first.
Export batch QA-229124 samples, all analyses.FormatCSV · one row per sample▾
CancelExport
Coach mark closes as the dialog opens · One raised surface · Right Closed · Same page, same coach mark
Toggle the dialog. In the top frame the coach mark was given a "very high" z-index so it would never be hidden, and now it floats above a modal it has nothing to do with.

Opening an overlay closes everything floating on the page. Menus, popovers, coach marks, and hover cards belong to the page, and when the page goes under a scrim, they go with it. Most of these close on an outside click anyway; the ones that don't (coach marks, persistent popovers, a "what's new" callout pinned to a button) are the ones that end up floating above a dialog, and they are almost always the product of someone giving a component a "very high" z-index so that it would "never be hidden." Section VII's scale makes that impossible: a coach mark is anchored and temporary, so it is level 2 on the popover layer, below every dialog.

The page under a modal is inert, not just dim. The scrim is what the user sees; the inert state is what the keyboard and assistive technology get, so that Tab can't wander onto a button under the scrim and a screen reader doesn't read the page behind the dialog. showModal() does both. A hand-built modal has to set inert on everything outside it, and a modal that dims the page without making it inert has a focus order that walks out of the dialog into a page the user can't see properly.

The only thing above the focused surface is a toast, and a toast never asks. Level 4 sits above dialogs so that a confirmation of what the dialog just did can be seen while it closes. That works only because a toast takes no focus and demands nothing: it reports, offers at most an Undo, and leaves on its own. A toast that needs a decision is a dialog in disguise, and it should be a dialog, because it is now a second raised thing asking a second question.

Disabled is not receded. Unavailability is a state of the control, shown by the control (Button Taxonomy covers disabled styling); a change of level claims the surface moved, which it didn't. The one surface-wide recession the system has is the scrim, and it means the whole page is unavailable, for exactly as long as the overlay is open.

One surface has focus, and it is the highest one that listens. Everything else is either part of the page, under the scrim, or a toast that will be gone in five seconds.

X. Inner Depth: Inset & Wells

Inset is honest in two places only: a control that holds a value or a moving part (an input well, a switch or slider track, a segmented control's tray), and a surface that sits below the page (a code block, a sunken tray). Everywhere else it's skeuomorphic noise. Going below the plane is the mirror image of going above it, and it claims the opposite thing: this is a container to put something into, rather than this is on top.

Site name
Input well · inset 0 1px 2px · Right
Switch · Sunken track, raised knob · Right
DayWeekMonth
Segmented · Tray −1, selected +1 · Right
Slider · Track −1, thumb +1 · Right
turbidity_ntu > 5.0 AND site IN ('weir', 'outfall')
Code · Sunken surface, tone only · Right
Card extruded and inset at once · Wrong
SummaryAnalysesChain of custody
Selected tab pressed in · Wrong
The honest pairs are the controls with a part that moves: the track sinks, the moving part rises one level, and the eye reads which part to grab.

The input well is the most common inset in the scale and the most useful: a 1 or 2px inset shadow at low alpha inside the border tells the eye that this box receives text rather than displays it. It belongs to the input chapter's border strategies (Text Inputs §IV) as an option, and it is the one inset most systems keep. Tracks follow the same logic: the switch's track and the slider's rail sink a little, and the knob and thumb rise to level 1, so the control reads as a channel with something to move along it. A segmented control is the clearest case: a sunken tray holding a raised selected pill, two levels apart, and the selection is unmistakable without any color.

A sunken surface without a control in it, such as a code block, a well holding an attachment list, or the tray of a kanban column, is better drawn by a tone than by an inset shadow: one step darker than the page in light mode, one step darker than level 0 in dark, on the --surface-sunken token. It is Atlassian's "sunken" surface, and it's the only level below 0 a system needs. Inset shadows on large surfaces look embossed; a tone just looks lower.

The failures are the same failure. Neumorphism extrudes and insets every surface with paired light and dark shadows, so nothing is above or below anything; it is the shadow-on-everything screen from section I, rendered in clay. The pressed-in tab uses inset to mean "selected," but inset means "a place to put something" or, briefly, "being pressed." A pressed state is an inset for the duration of the press, :active only, and gone the moment the pointer lifts; a selected state is a mark, an underline or a fill, and stays.

Below the plane means "put something here." Use it for wells and tracks, the places that receive or contain, and keep it off everything that merely displays.

XI. Auditing a Screen

Count the distinct shadows on a screen: the count should equal the number of levels in use, and on most screens at rest that number is zero or one. Here is section I's screen after one pass of the audit: same components, same content, two shadows.

SamplesBatchesSamplesReportsMK
Batches / Lake Arden intakeBatch QA-2291
FilterExportNew sample
AR-114Inlet north4.2NTULogged 08:12
Open sampleDuplicateMove to batch…Archive sampleL2
AR-115Inlet south3.8NTULogged 08:20
AR-116Weir pool6.1NTULogged 08:41
AR-117Spillway2.9NTULogged 09:03
AR-118Pump house5.4NTULogged 09:15
AR-119Outfall7.0NTULogged 09:32
Sample AR-120 logged UndoL4
2 distinct shadows · 2 levels in use · Nothing on the page raised at rest · Menu on the popover layer After the audit · Same components, same content · Shadows taken from the scale The menu now reads as above the grid without being any darker than before, because nothing around it is competing.
CheckFound in §IFix
Distinct shadowsSix, all hand-written, pure blackTwo, both from the scale: level 2 on the menu, level 4 on the toast.
Raised at restTop bar, buttons, cards, inspectorAll flat. Bar and inspector take a hairline; cards a hairline on a canvas one step darker (§II, §V).
Same claim, different truthMenu wore the cards' shadowMenu is the only floating surface, so its level 2 shadow is now legible (§IV).
StackingMenu trapped by the cards' hover transformTransform removed from the cards; menu on --z-popover, rendered outside the card in production (§VII).
HoverCards lift to a fourth shadowNo lift: the cards hold a menu button, so they aren't one target (§V).
ToastBlack shadow at .45 to be seen over the noiseLevel 4 at its normal alpha; with a flat page, it doesn't need to shout.

The Method

Count the shadows. Every distinct computed box-shadow on the screen should be one of the scale's levels, and the number of distinct values should be the number of levels in use. A browser console makes the count exact rather than a matter of squinting:

const seen = new Map(); document.querySelectorAll('*').forEach(el => { const s = getComputedStyle(el).boxShadow; if (s !== 'none') seen.set(s, (seen.get(s) || 0) + 1); }); console.table([...seen].map(([shadow, count]) => ({ shadow, count }))); // one row per level, or a bug

Find everything raised at rest. With no menu open, no dialog, no toast, and nothing being dragged, the count should be zero, or one if a header is scrolled or a control has a thumb. Anything else that wears a shadow is a page surface making a false claim: give it a hairline or a tone.

Find the raw z-indexes. Search the codebase for z-index followed by a digit. Every hit outside the token file is a defect; anything above the scale's top is a stacking-context workaround someone couldn't explain, and the explanation is usually a transform or an opacity on an ancestor (§VII).

Open every overlay from every overlay. A select in each dialog, a date picker in each drawer, a menu on a page while a toast is showing. Check that the child is above its parent, unclipped, and carries its own level's shadow, and that nothing from the page floats above a scrim.

Switch to dark mode and repeat. Every level should still be distinct. If a menu disappears into the card under it, the surface tokens are being shared between modes or a component picked its own color (§VI).

On a Phone

Mobile is a reducing layer here as everywhere else, and it reduces the scale to three levels in practice. Hover lift disappears, since there is no hover. Popovers and menus that would float at level 2 on desktop usually become bottom sheets, which are drawers from the bottom edge, at level 3 with a scrim, because a small anchored surface is hard to hit and easy to cover with a thumb. What survives is the flat page, the sticky header's level 1 while scrolled, the overlay at level 3, and the toast at 4. The z-index scale doesn't change at all, which is the point of having one.

Count the shadows before arguing about them. A screen at rest should have almost none, and every one it has should be the name of a level.

XII. The Decision Sequence

Decide depth for the system once, in this order, and components inherit it; decided per component, it drifts into section I's screen within a release. Each step depends on the ones before it.

1
Draw the page flatEverything that is part of the page is level 0. Choose a hairline or a tone for each region boundary: frame regions, cards, rows.
2
Name the levelsFive, by meaning: flat, raised, floating, overlay, top. Write down who sits at each, at rest and while active.
3
Build one shadow pair per levelKey layer for the edge, ambient for the height. Light from above, a tinted dark, blur 2–3× the offset, negative spread.
4
Build the dark rampA lighter surface per level, a brighter top edge, black shadows doing a smaller job. Surface and shadow tokens per mode.
5
Name the layersEight z-index tokens, each mapped to one level; the tooltip the only exception. Top layer where available, portal to the root otherwise.
6
Fix the overlay rulesScrim exactly when the page stops responding, at 40% tint or 60% black. Children stack above parents by opening order. One nesting, for confirmation.
7
Fix the attention rulesOne raised surface takes input at a time. Opening an overlay closes the page's floating things. Only a toast goes above, and it never asks.
8
AuditCount distinct shadows and raw z-indexes on the busiest screens, in both modes, each release.

Steps one through seven are tokens and component contracts; they change rarely. Step eight is the habit that keeps them true, and it is short: one console snippet, one search, one theme switch.

What the Best Systems Avoid

Shadowed card grids. Twelve surfaces each claiming to be on top, so the one surface that is (the open menu) has nothing left to say. Cards rest flat with a hairline.

Shadow strings in components. A box-shadow with literal values anywhere but the token file. Each one is a level nobody named, and six of them are section I's screen.

z-index: 9999. The number is a confession that someone fought a stacking context and didn't find it. Name the layer and render the overlay at the root.

Light-mode shadows ported to dark mode. The scale survives, but every level renders the same. Dark mode needs its own surface ramp and edge.

Two raised things at once. A coach mark over a dialog, a popover left open under a drawer, a toast that asks a question. One surface listens at a time.

Neumorphic and embossed surfaces. Inset and outset on everything, so nothing is above or below anything. Inset is for wells and tracks.

This part has been about the static z-axis: which surface sits at which level, and in what order. Part II takes up materials and movement: the two materials a surface can be made of and why translucency is not a third, how a surface travels between levels as it opens and closes, and where elevation hands off to Motion & Easing.

Part I of Elevation & Depth.
A flat page is not the absence of depth. It is what lets the one raised thing be seen.