Enterprise Verified
Academy Frontend Web Development CSS CSS Z-index & Stacking Context
Advertisement
Google AdSense Slot (LEADERBOARD)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Stacking 7 min read • Chapter 14 of 23

CSS Z-index & Stacking Context

The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order.

Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items.

Example

<!DOCTYPE html>
<html>
<body style="font-family:sans-serif;padding:20px;">
    <div style="position:relative;">
        <div style="position:absolute;left:20px;top:20px;width:100px;height:100px;background:#ef4444;z-index:1;">Layer 1</div>
        <div style="position:absolute;left:50px;top:50px;width:100px;height:100px;background:#10b981;z-index:2;color:white;padding:8px;">Layer 2 (z-index: 2)</div>
    </div>
</body>
</html>
Try it Yourself >> Opens live sandboxed code editor
Advertisement
Google AdSense Slot (IN-ARTICLE)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php

Community Q&A & Discussion

No questions yet. Be the first to start the discussion!
Enterprise Operations Suite

Streamline Employee Payroll & Attendance Operations

Eliminate manual spreadsheet errors. Integrate automated attendance tracking, EPF/ESI statutory calculations, and custom GST invoices.

Copied!

AI Learning Assistant

Ready to explain & guide

Hello! I am your MBS Digital AI Tutor. Ask me to explain concepts, review code, or suggest debugging steps.

Quick Starters:
AI Tutor is thinking...