Z-Index Property

Last updated: 2026-09-13

z-index Z-Index Property

The z-index property controls the stacking order of positioned elements along the z-axis, perpendicular to the screen; elements with a higher value are rendered above those with lower values. It is typically used with position for layered UI such as modals, dropdowns, and overlays.

Category
Initial Valueauto
InheritedNo
Applies Topositioned
Animation Typeinteger
CSS VersionCSS2
StatusStandard

📝 Syntax

z-index: auto | <integer>;

⚙️ Values

ValueTypeDescription
autoKeywordDoes not create a new stacking context.
<integer>TypeAn integer stacking order; larger values render on top.

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
z-index v1 v12 v1 v1 v1
Supported in all major browsers
Warning: z-index only affects elements with a non-static position; setting it on elements in normal flow has no effect.
Important: z-index comparisons only work within the same stacking context. Values in different stacking contexts cannot be compared directly, and a child's z-index cannot exceed its parent stacking context's boundary.

❓ FAQ

QWhat z-index value should I use?
AFor most business cases, 1 to 10 covers almost everything; larger projects use round numbers or thousands, with modals at 9999 and overlays at 1000. Avoid abusing extreme values like 999999: once several components compete by bumping z-index higher, the numbers spiral out of control and become unmaintainable. It is better to keep z-index within a small range and manage levels with variables or conventions.
QWhy isn't z-index working?
ACommon causes: first, the element has no position, since z-index only affects positioned elements and flex or grid items; second, a parent creates a stacking context, via opacity below 1, transform, filter, and so on, confining the child's z-index within it; third, the two elements are not in the same stacking context or share no common parent, so they cannot be compared. Debug these three in order.
QWhat is a stacking context?
AA stacking context is an isolated zone of stacking: z-index ordering only applies within that zone. It is created by positioned elements with a non-auto z-index, opacity below 1, transform, filter, and several other properties. A child's z-index can never escape its parent stacking context's boundary, which is exactly why a modal often fails to cover a backdrop. The fix is usually to move the overlapping element out of that context.
QDoes z-index only work on positioned elements?
ATraditionally yes, z-index applies to positioned elements, meaning relative, absolute, fixed, or sticky. In flex and grid layouts, however, items can use z-index to control visual order even without being positioned. Elements in normal flow that are not positioned cannot be reordered with z-index, so if you need to layer ordinary elements, add position:relative first, which costs nothing in layout terms and unlocks z-index.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏