z-index: plainly explained.

The z-index is a CSS property that sets the stacking order of overlapping elements. How stacking contexts work and why z-index sometimes fails.

Design · Updated Nov 7, 2026

DEFINITION

The z-index is a CSS property that controls the stacking order of overlapping elements: a higher z-index sits in front of a lower one.

CATEGORY

Design

RELATED

CSS Grid, Flexbox

Summarize this page with AI

The z-index is a CSS property that controls the stacking order of elements that overlap on a page. An element with a higher z-index appears in front of one with a lower value. It answers a simple question: when two things sit on top of each other, which one is visible?

01

How stacking works

z-index only applies to positioned elements (those with a position other than static) and to flex or grid children. Values can be positive or negative, and the browser paints higher values on top.

  • .modal { position: fixed; z-index: 1000; }
  • Without a z-index, elements paint in the order they appear in the HTML.
02

The painting order

The browser paints in layers: first backgrounds, then non-positioned blocks, then floats, then positioned elements ordered by z-index. When two elements share the same z-index, the one later in the HTML wins.

03

Stacking contexts

A stacking context is a group of layers that stack together as a unit. Several properties silently create one, which is the usual source of confusion.

TriggerExample
Positioned element with z-indexposition: relative; z-index: 1
Opacity below 1opacity: 0.9
Transformtransform: translateZ(0)
Filterfilter: blur(2px)
will-changewill-change: transform
04

Why z-index fails

Most problems come from a missing position or from a parent that created a stacking context and trapped the child inside it. A z-index of 9999 cannot escape its parent's context, so it still sits behind a sibling of that parent with a higher value. Inside a context, child z-index values are only compared with each other.

05

Best practices

  • Only add z-index where elements actually overlap.
  • Use a small, documented scale (for example 10, 100, 1000) instead of arbitrary large numbers.
  • Keep track of which components create a stacking context (transforms, opacity, filters), so surprises are easy to diagnose.
06

z-index at BeBranded

At BeBranded we keep stacking predictable with a clear layering scale, so menus, modals and sticky bars never fight each other. It is part of the tidy, maintainable front-end we deliver through our design work.

FAQ

Questions about z-index.

Another question?

Write to us
What is z-index in CSS?
The z-index is a CSS property that sets the stacking order of overlapping elements. A higher z-index appears in front of a lower one.
What is a stacking context?
A stacking context is a group of layers that stack as a unit. Properties like a positioned element with a z-index, an opacity below 1, or a transform create one. Child z-index values only compete within the same context.
Why is my z-index not working?
Usually because the element has no position (it must be non-static), or because a parent created a stacking context that traps the element. Check the parent's opacity, transform and z-index.
Can z-index be negative?
Yes. A negative z-index places an element behind others in the same stacking context, which is useful for background layers.
Does z-index need position?
For most elements, yes: z-index applies to positioned elements (position other than static). Flex and grid children are exceptions where z-index also works.
Is there a maximum z-index value?
The practical maximum is very large (2147483647), but using huge values is a bad habit. A small, consistent scale is easier to maintain.

Related

Related terms, and where to go next.

How to choose a web design agency that fits your growth stage
Design

How to choose a web design agency that fits your growth stage

Choose a web design agency by growth stage, scope, process, SEO, and support. Use a practical framework and checklist.

Read the article
Claude Design: what it changes for your website
AI & automation

Claude Design: what it changes for your website

Claude Design by Anthropic: what the tool actually does, its concrete limits, the pipeline to Webflow, and why a prototype is not a product.

Read the article
BeBranded
UX/UI

Responsive design: complete guide for 2026

Responsive design: definition, technical principles, breakpoints, Flexbox, Grid, fluid typography, how Webflow handles it, mistakes and best practices.

Read the article

Let’s talk

Tell us what you want to build.

Thirty minutes with the people who will work on your project. You leave with a clear view of the scope, the timeline and the next steps.

What happens next

  1. 1A 30-minute callWe listen to your goals, your constraints and your context.
  2. 2A clear scopeWe map what is worth doing first, and what it takes.
  3. 3A costed proposalYou decide, with no commitment and no sales pitch.