Cyber Code Academy
Tutorials Academy Courses
Home / CSS / CSS z-index and Stacking Contexts

CSS z-index and Stacking Contexts

Using z-index

.header { position: sticky; top: 0; z-index: 20; }
.dialog-backdrop { position: fixed; inset: 0; z-index: 100; }
.dialog { position: fixed; z-index: 101; }

The z-index value is compared within stacking contexts. A large number in a nested stacking context cannot always rise above elements in a different context.

Stacking contexts can be created by properties including positioned elements with a non-auto z-index, transforms, opacity below 1, and several modern layout properties.

Practice

Build a modal overlay and ensure the dialog appears above its backdrop.

Want to learn this professionally?

Explore practical IT training at Cyber Code Academy.

View Academy Courses