Style zIndex property
The Style object
Definition and Usage
The zIndex property sets or returns the stacking order of a positioned element.
An element with a higher stacking order (1) will always be in front of an element with a lower stacking order (0).
**Tip:** A positioned element is an element whose position property is set to: relative, absolute, or fixed.
Syntax
Set the zIndex property:
Object.style.zIndex="auto|
number
|inherit"
Return the zIndex property:
Object.style.zIndex
| Value | Description |
|---|---|
| auto | Default. The browser determines the stacking order of the element (based on the order of the elements in the document). |
| number | An integer that defines the stacking order of the element. Negative values are allowed. |
| inherit | The value of the zIndex property is inherited from the parent element. |
Browser support





All major browsers support the zIndex property.
Tips and Notes
**Tip:** This property is very useful if you want to create overlapping elements.
Example
Example
Change the stacking order of an element:
This is a heading
The default z-coordinate is 0, and a z-coordinate of -1 has lower priority.
Try it »
The Style object