The z-index property sets the stack level of a box along the z-axis. When positioned boxes overlap, a higher value paints in front of a lower one.
It applies to elements with position other than static, and to flex or grid items. The initial value is auto. It is not inherited. An integer value also creates a local stacking context.
Baseline Widely available.
Standard CSS 2 property. Use small, intentional integers. Huge values like 9999 are rarely needed and harder to maintain.
Syntax
CSS Syntax
syntax.css
z-index:auto | <integer> | initial | inherit;
Integers may be positive, 0, or negative. Decimals are not valid.
Values
Property Values
Value
Description
Try it
auto
Default. Stack level 0; no new stacking context from z-index
Prefer a small local scale. Competing 99999 values make overlays hard to debug.
Compatibility
Browser Support
z-index is a browser layout property. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Long supported
z-index
Supported in Chrome, Firefox, Safari, Edge, Opera, Samsung Internet, and Internet Explorer. Universal across modern and legacy browsers.
99%All major browsers
Google ChromeYes
Full support
Mozilla FirefoxYes
Full support
Apple SafariYes
Full support
Microsoft EdgeYes
Full support
OperaYes
Full support
Samsung InternetYes
Full support
Internet Explorer6+
Full support
z-indexUniversally supported
Bottom line: Safe everywhere. Focus on stacking contexts and positioning more than version numbers. Not a server runtime API.
Remember
Key Takeaways
Role: set the stack level of overlapping positioned (or flex/grid) boxes.
Values:auto or an integer (positive, 0, or negative).
Initial value:auto. Not inherited. Integers create a local stacking context.
Tip: fix stacking contexts before raising numbers — 9999 rarely fixes a trapped child.
One line:z-index decides which overlapping positioned box paints on top — inside its stacking context.
Frequently Asked Questions
It sets the stack level of a positioned element (or a flex/grid item) along the z-axis. Higher values paint in front of lower values when boxes overlap.
The initial value is auto. The element uses stack level 0 and does not create a new local stacking context from z-index alone.
No for normal flow boxes. The element usually needs position other than static. Flex and grid items can also use z-index without repositioning.
A stacking context is an isolated layer group. Child z-index values compete only inside that group, not against the whole page.
Yes. Negative integers place a box behind siblings in the same stacking context, often used for backgrounds.
It is Baseline and long-supported in all major browsers, including Internet Explorer. It is a browser layout property, not a Node.js feature.