Open In App

HTML | DOM Style zIndex Property

Last Updated : 05 Jun, 2022
Like Article

The Style zIndex property is used for set or return the stack order of a positioned element. The element which has a lower stack order will be behind of another element with higher stack order. For example, the element with stack order(1) will be in front of the element with stack order(0). The Style zIndex property is generally used when the user wants to create overlapping elements. 

Syntax :

  • To get the property:;
  • To set the property: = "auto|number|initial|inherit"

Property Values:

  • auto: It is used to let the browser determine the stack order of the element.
  • number: It uses an integer that defines the stack order of the element.
  • initial: It is used to set the default value.
  • inherit: It is used to inherit property from its parent.

Return Values: It returns a string value, which represents the stack order of an element.

Below program illustrates the Style zIndex property : 

Example: Changing the stack order of an <img> element. 


<!DOCTYPE html>
    <title>Style zIndex Property</title>
        #MyImage {
            position: absolute;
            left: 200px;
            top: 80px;
            z-index: -1
        h1 {
            color: green;
        h2 {
            font-family: Impact;
        body {
            text-align: center;
    <h2>Style zIndex Property</h2>
    <img id="MyImage" src=
    <button type="button" ondblclick="stack()">
      Bring Logo In The Front
    <p>This is the logo of Geeksforgeeks.It has z-index as 0.</p>
    <p>To bring the logo in the front,
    double-click the "Bring Logo In The Front" button.</p>
        function stack() {
            document.getElementById("MyImage").style.zIndex = "1";


  • Before clicking the button:


  • After double clicking on the button:


Supported Browsers: The browser supported by HTML | DOM Style zIndex Property are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 4 and above
  • Firefox 1 and above
  • Opera 4 and above
  • Apple Safari 1 and above

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads