Style zIndex Property
- Previous Page widows
- Next Page alignContent
- Go to Parent Directory HTML DOM Style Object
Definition and Usage
zIndex
Sets or returns the stacking order of the positioned element.
elements with a higher stacking order (1) are always in front of elements with a lower stacking order (0).
Tip:Positioning elements are Position Property Set to:relative
,absolute
or fixed
of the element.
Tip:This property is very useful if you want to create overlapping elements.
See Also:
CSS Tutorial:CSS Positioning
CSS Reference Manual:z-index Property
Example
Example 1
Change the stacking order of the <img> element:
document.getElementById("img1").style.zIndex = "1";
Example 2
Change the z-index property value of the <div> element:
document.getElementById("myDIV").style.zIndex = "-1";
Example 3
Returns the z-index property value of the <img> element:
alert(document.getElementById("img1").style.zIndex);
Syntax
Return zIndex Property:
object.style.zIndex
Set zIndex Property:
object.style.zIndex = "auto|number|initial|inherit"
Property Value
Value | Description |
---|---|
auto | The browser determines the stacking order of an element (based on its order in the document). Default. |
number | An integer defining the stacking order of an element. Negative values are allowed. |
initial | Sets this property to its default value. See initial. |
inherit | Inherits this property from its parent element. See inherit. |
Technical Details
Default value: | auto |
---|---|
Return value: | A string indicating the stacking order of an element. |
CSS Version: | CSS2 |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Previous Page widows
- Next Page alignContent
- Go to Parent Directory HTML DOM Style Object