Skip to content
Learn Netverks

Lesson

Step 26/31 84% through track

stacking-and-z-index

Stacking contexts and z-index

Last reviewed Jun 1, 2026 Content v20260601
Track mode
iframe_html
Means
HTML preview sandbox
Reading
~2 min
Level
advanced

This lesson

This lesson teaches Stacking contexts and z-index—the ideas, syntax, and habits you need before moving on in HTML & CSS.

Without a solid grasp of Stacking contexts and z-index, you will repeat mistakes in HTML & CSS exercises and on real pages or scripts.

You will apply Stacking contexts and z-index in contexts like: Landing pages, dashboards, marketing sites, and portfolio pieces built without a framework.

Read the lesson, edit HTML/CSS in the playground, press Run to preview, then answer the lesson MCQs.

When intermediate lessons feel comfortable and you are ready for production-style trade-offs.

z-index only compares elements within the same stacking context. Senior developers debug overlays by finding which ancestor created a new context—not by raising numbers blindly.

What creates a stacking context (common triggers)

  • position with z-index not auto
  • opacity less than 1
  • transform, filter, isolation: isolate
  • Flex/grid items with z-index

Layering strategy for apps

  1. Define tokens: --z-dropdown: 100, --z-modal: 200, --z-toast: 300.
  2. Keep overlays in a top-level portal or dedicated root when frameworks allow.
  3. Document which component owns which layer.

Challenge

Fix the buried dropdown

  1. In the playground, the menu is clipped/hidden—find the parent with overflow: hidden or a low stacking context.
  2. Fix by moving the menu in the DOM or adjusting overflow/isolation on the right ancestor.

Done when: the dropdown appears above the card border and remains clickable.

Go deeper — Interview answer: “z-index 9999 did nothing” (intermediate / experienced)

Strong answer: “I inspected the stacking context tree. A parent with transform and z-index: 1 trapped the modal. I moved the overlay to the document root / raised the correct context / removed accidental opacity on a wrapper.” Weak answer: “I kept increasing z-index until it worked.”

Interview prep

Debugging steps when overlays fail?

Inspect stacking contexts, check overflow/transform on ancestors, verify portal placement, use documented z-index scale—not infinite 9999.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What part of this lesson needs a second read?
  • What would you try differently in a real project?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump