On this page
Depth tells people which surface owns the next action. A card groups content on the page. A popover belongs to the control that opened it. A modal dialog asks people to finish or dismiss a task before returning to the page.
Switch between the three surfaces in the same workspace. Turn Contact shadow and Ambient shadow off one at a time to see what each adds.
Choose elevation by role
Start with a short list of named roles. If your system already has one, look at where its tokens are used before adding another.
- Page and card. Keep repeated cards close to the page. On a dense list or dashboard, try spacing or a surface tint first. Reserve a short shadow for a card that needs to read as one group.
- Popover. Position it near the trigger and leave enough nearby content visible for orientation. Use a tighter contact shadow plus a wider falloff than a card. Test the placement against every edge of the viewport.
- Modal dialog. Use it when the page must wait for a decision. A backdrop signals that the rest of the interface is temporarily inactive. The dialog also needs to manage focus and provide a clear way to close.
A hover treatment can make a clickable card feel responsive. Check the same action with a keyboard and on touch, where hover may never happen. Give focus a visible indicator of its own.
Occlusion beats outline
Occlusion is the overlap that tells you which surface sits in front. In the example, the menu covers part of the workspace and casts onto it. That relationship holds even when both shadows are off. If the order feels unclear, adjust the placement before increasing shadow opacity.
Build the shadow in two passes:
- Contact. A small downward offset and tight blur define the edge nearest the surface behind it.
- Ambient. A wider, softer falloff suggests more separation. Use negative spread to keep a longer shadow concentrated below the surface when the corners look muddy.
In CSS, the first shadow in a comma-separated list paints on top. Put the sharper edge or contact shadow before the wider ambient shadow. Check the effect on both your lightest and darkest surfaces. On dark backgrounds, a slightly lighter surface and a faint inset edge can do more work than a stronger black shadow. See Shadows, Not Borders for a closer look at those layers.
Stacking order and focus
Visual elevation and CSS paint order are separate. A large shadow can make a card look raised while an ancestor still clips it. Before increasing z-index, check the symptom:
- The shadow or menu is cut off. Inspect the ancestor chain for clipping, particularly
overflow: hiddenor a scroll container. A higherz-indexcannot undo an ancestor’s clip. Keep the needed scroll boundary and move the overlay outside it, or use a browser top-layer primitive. - The whole surface paints behind another layer. Inspect the stacking contexts around both surfaces. A transform, opacity below 1, or a positioned element with a non-auto
z-indexcan create a context. A child’sz-indexis resolved inside that context. Fix the relationship between the ancestor layers. - The surface looks right but keyboard users get lost. Check where focus starts, what Tab can reach, and where focus goes after dismissal. A sticky header or footer must leave the focused control at least partly visible for WCAG AA. Aim to keep the full control and its indicator in view.
Use a native popover for a non-modal flyout when its behaviour fits. Use <dialog> with showModal() when the rest of the page should be inactive. Both can use the browser’s top layer. A shadow changes neither stacking order nor keyboard behaviour.
Usage
Copy the CSS for the role you tested above and apply .depth-surface to that surface. The recipe is a starting point for the shadow alone. Give the card, popover, or dialog its own surface colour, placement and interaction pattern.
Here is a minimal modal with an accessible name and a native close action. The trigger opens it in the top layer. The close handler returns focus to the trigger.
<button type="button" id="open-review">Open review dialog</button>
<dialog id="review-dialog" class="depth-surface" aria-labelledby="review-title">
<h2 id="review-title">Review the brief</h2>
<form method="dialog">
<button type="submit">Close</button>
</form>
</dialog>
const trigger = document.querySelector("#open-review");
const dialog = document.querySelector("#review-dialog");
trigger.addEventListener("click", () => dialog.showModal());
dialog.addEventListener("close", () => trigger.focus());
Before you ship
Test an open popover inside a scrolled panel and near a viewport edge. Compare each role in light and dark mode, then repeat the flow with Tab, Shift+Tab and Escape where applicable. Check that opening or closing an overlay leaves focus somewhere useful. If you animate the change, honour reduced motion and confirm the layer order is still understandable with the animation off.