positioning

z-index

Sets the stack order of positioned elements along the z-axis. Higher values are drawn in front of lower ones within the same stacking context.

z-index: auto | <integer>

Common values

Value Effect
auto Uses parent stacking order; no new context
0 Creates a stacking context at the baseline layer
10 Common value for dropdowns and popovers
9999 Convention for always-on-top overlays
-1 Sends element behind normal siblings

Examples

.modal { position: fixed; z-index: 1000; }

Modal renders above the page content

.dropdown { position: absolute; z-index: 20; }

Popover appears above nearby elements

.backdrop { position: fixed; z-index: -1; }

Decorative background sits behind content

Gotcha

z-index only applies to positioned elements (position not static) or flex/grid items; a new stacking context traps children inside it.

Related properties

← All CSS properties · CSS selectors · Grid vs Flexbox