CSS Tutorial
Z-index is a CSS property that determines the stacking order of elements on a webpage. Higher z-index values indicate that elements appear closer to the user, obscuring elements with lower values.
.layer1 {
position: absolute;
z-index: 1;
background-color: red;
}
.layer2 {
position: absolute;
z-index: 2;
background-color: blue;
}
position: absolute
property positions elements absolutely within their parent container.z-index
property assigns a stacking order to the elements:layer1
has a z-index of 1, so it will appear above the normal flow of the document.layer2
has a higher z-index of 2, so it will stack above layer1
and be visible on the webpage.Z-index can impact accessibility by ensuring that important elements are visible to users. For example, a modal dialog should have a high z-index to prevent users from interacting with other page elements behind it.