Concepts 🚀 Project 🧮 Labs
🧮 Labs / CSS / z-index — stacking order

z-index — stacking order

z-index controls which element appears on top when they overlap. Higher = on top. Only works on positioned elements.

style.css v3.1
style.css — the CSS rules
index.html — the HTML structure (what the CSS targets)
Live preview updates as you type
🧠 How it works

z-index only works on positioned elements (position: relative/absolute/fixed/sticky). On static elements, z-index is ignored. Higher z-index = closer to the user (on top). Default z-index is 0 (or 'auto'). Modal dialogs typically use z-index: 1000+ to appear above everything. Inside a stacking context, only siblings compete — a child of a low-z-index parent cannot escape above a high-z-index sibling of the parent.

✏️ Try these changes
  • Change .red z-index: 1 to z-index: 10
    → red jumps to the top
  • Change .blue z-index: 3 to z-index: 0
    → blue drops to the bottom
  • Change .green z-index: 2 to z-index: -1
    → green goes BEHIND the page background (becomes invisible)