HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. CSS Z-index

CSS Layout

CSS Z-index

The CSS Z-index property controls the stacking order of positioned elements on a webpage.

When two or more elements overlap, the element with the higher z-index value appears in front of the others. The supporting concepts are explained in CSS Position and Normal Flow.

Think of z-index as layers stacked on top of each other:

  • Higher z-index = Closer to the user
  • Lower z-index = Further behind

Z-index is commonly used for:

  • Navigation menus
  • Popups and modals
  • Tooltips
  • Dropdown menus
  • Floating buttons

Syntax

CSS Z-index Syntax

css

selector {
    z-index: value;
}

CSS Z-index Example

css

.box {
    position: absolute;
    z-index: 10;
}

This places the element above elements with lower z-index values.

Attributes

PropertyDescriptionExample
z-indexSets stacking orderz-index: 5;
z-indexHigher value appears in frontz-index: 100;
z-indexLower value appears behindz-index: 1;
z-indexNegative stacking orderz-index: -1;
z-indexDefault stacking orderz-index: auto;

Example

CSS Z-index Complete Example

html

<!DOCTYPE html>
<html>
<head>
    <title>CSS Z-index Example</title>
    <style>
        .container {
            position: relative;
            height: 250px;
        }
        .box1 {
            position: absolute;
            top: 20px;
            left: 20px;
            width: 200px;
            height: 150px;
            background-color: lightblue;
            z-index: 1;
        }
        .box2 {
            position: absolute;
            top: 60px;
            left: 80px;
            width: 200px;
            height: 150px;
            background-color: orange;
            z-index: 2;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="box1">Box 1 (z-index: 1)</div>
        <div class="box2">Box 2 (z-index: 2)</div>
    </div>
</body>
</html>

Browser Support

Feature
Chrome
Edge
Firefox
Safari
z-index11211

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8.

Notes

  • z-index only works on positioned elements: position: relative, position: absolute, position: fixed, and position: sticky.
  • Elements with higher z-index values appear above lower values.
  • Negative z-index values can place elements behind others.
  • z-index: auto uses the default stacking order.
  • Avoid extremely large z-index values unless necessary.

Common Layering Example

ElementTypical Z-index
Page Content1
Sticky Header100
Dropdown Menu1000
Modal Window10000
Tooltip100000

Conclusion

The CSS Z-index property is essential for controlling the stacking order of overlapping elements. By using z-index with positioned elements, you can create dropdowns, modals, tooltips, and other layered interface components that appear correctly above or below other content.

PreviousCSS OverflowNextIntrinsic Sizing