- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - Layers
In CSS, you can create layers of various divisions. CSS z-index property can be combined with the position property to create a layer effect.
The z-index property specifies the stacking order of an element. You can specify which element should come on top and which at bottom.
A z-index property can help you to create more complex webpage layouts.
CSS Layers - With z-index Property
The following example demonstrates how to create layers using z-index property. The elements with higher z-index value are positioned above the elements of lower z-index value −
<html> <head> <style> .box1 { position: absolute; height: 100px; width: 100px; background-color: red; z-index: 1; padding: 3px; left: 10px; top: 10px; } .box2 { position: absolute; height: 100px; width: 100px; background-color: lightblue; z-index: 2; padding: 5px; margin: 10px; left: 50px; top: 30px; } .box3 { position: absolute; height: 100px; width: 100px; background-color: yellow; z-index: 3; padding: 5px; margin: 20px; left: 80px; top: 50px; } p { margin-top: 200px; } </style> </head> <body> <p>The element with z-index value of 1 appears behind the elements with the z-index value of 2 and 3.</p> <div class="box1"> CSS z-index: 1 </div> <div class="box2"> CSS z-index: 2 </div> <div class="box3"> CSS z-index: 3 </div> </body> </html>
CSS Layers - Images and Text
The following example demonstrates how to create layers using z-index property. Higher z-index elements are positioned above lower z-index elements −
<html> <head> <style> img { height: 200px; width: 200px; position: absolute; left: 0px; top: 0px; z-index: 2; margin: 5px; } h1 { margin-top: 30px; z-index: 1; color: red; } </style> </head> <body> <img src="images/shop.png"> <h3>Tutorialspoint</h3> </body> </html>
CSS Layers - Without z-index Property
The following example demonstrates how to create layers without using z-index property −
<html> <head> <style> .box1 { position: absolute; height: 210px; width: 210px; background-color: red; padding: 10px; left: 10px; top: 10px; } .box2 { position: absolute; height: 150px; width: 150px; background-color: lightblue; padding: 10px; margin: 10px; left: 30px; top: 30px; } .box3 { position: absolute; height: 100px; width: 100px; background-color: yellow; padding: 5px; margin: 10px; left: 60px; top: 60px; } </style> </head> <body> <div class="box1"> Box 1 </div> <div class="box2"> Box 2 </div> <div class="box3"> Box 3 </div> </body> </html>