![]() |
VOOZH | about |
CSS z-index is used to control the stacking order of overlapping elements, which decides whether an element appears on top or behind others based on their assigned value.
These are the values of the z-index property and their descriptions:
| Value | Description |
|---|---|
auto | The stack order is equal to that of the parent (default). |
number | The stack order depends on the number. |
initial | Sets the property to its default value. |
inherit | Inherits the property from the parent element. |
The auto value applies the default stacking order without explicitly defining the stacking context.
Specifying numerical values controls the stacking order. Higher values stack above lower ones.
The blue box (z-index: 2) appears above the red box (z-index: 1).
The initial value resets the z-index to its default value of auto.
The red box follows the default stacking order since z-index: initial resets to auto.
The inherit value ensures the element inherits its z-index value from its parent.
The child element inherits the z-index value (5) from its parent.
When working with multiple stacking contexts, the z-index applies only within its context.
The red box stacks above the blue box within the same stacking context defined by the parent element.