Z-index

Also called stacking order or z-order

A CSS property that decides which element appears on top when elements overlap, with higher numbers sitting closer to the viewer.

What is Z-index?

The screen is flat, but elements often overlap: a dropdown over a card, a modal over the page, a sticky header over scrolling content. z-index sets the stacking order, so an element with z-index: 3 covers one with z-index: 2. It works on positioned elements (relative, absolute, fixed, or sticky) and on children of flex and grid containers.

The usual surprise is the stacking context. Properties such as transform, filter, opacity below 1, or a z-index on a positioned parent seal an element and its children into their own layer. A child with z-index: 9999 still cannot rise above anything outside that layer, which is why a menu can hide behind the header no matter what number you give it.

Pick a small, named scale and stick to it, for example 10 for sticky headers, 20 for dropdowns, 30 for overlays, 40 for modals, and 50 for toasts. Rendering menus and modals at the end of the page body with a portal avoids most stacking context problems.

All terms

Modal

A window that opens over the page, dims everything behind it, and blocks the rest of the interface until you finish or dismiss it.

Dropdown menu

A list of actions that drops down from a button when you click it, then closes as soon as you pick one.

Sticky header

A top bar that stays pinned to the top of the screen while the page scrolls underneath it, so navigation is always one click away.

Overflow

A CSS property that decides what happens when content is bigger than its box: spill out, get clipped, or scroll inside it.