z-index property is used to layer elements in front or behind each other along a "z-axis".
This is referred to as the 'stack level'. By using the
z-index property, we can specify the stack level of a box in within its current stacking context.
Generally speaking, you can position an element in front of another by giving it a higher
For example, an element with a
200 will render in front of an element with a
100 (or even
199 for that matter). And likewise, an element of
100 will render in front of an element of say
50 (or even
z-index property only applies to positioned elements.
- Specifies that the stack level of the generated box in the current stacking context is
0. The box does not establish a new stacking context unless it is the root element.
- Specifies the stack level of the generated box in the current stacking context. The box also establishes a new stacking context.
In addition, all CSS properties also accept the following CSS-wide keyword values as the sole component of their property value:
- Represents the value specified as the property's initial value.
- Represents the computed value of the property on the element's parent.
- This value acts as either
initial, depending on whether the property is inherited or not. In other words, it sets all properties to their parent value if they are inheritable or to their initial value if not inheritable.
- Initial Value
- Applies To
- Positioned elements
- Yes (see example)
- CSS Positioned Layout Module Level 3 (W3C Working Draft, 17 May 2016)
- CSS Level 2.1 (W3C Recommendation 07 June 2011)