The CSS reference

"z-index" - css property (v. css 2)

  • Indicates the stack order of an element
  • Initial value: auto
  • The property is not inherited
  • HTML usage: positioned elements
  • Browsers that support the z-index - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari

Possible z-index values:

value Comments CSS
auto Follow the normal calculated stack order. 2
integer This integer is the stack level of the generated box in the current stacking context. The box also establishes a new stacking context. 2
inherit Will inherit the value from parent specification. 2

Property "z-index" example:

<!DOCTYPE HTML >
<html>
  <head>
    <style   type="text/css">
      .pos1 { position: absolute;
              left: 20px;
              top: 20px;}
      .pos2 { position: absolute;
              left: 180px;
              top: 20px;}
      .pos3 { position: absolute;
              left: 20px;
              top: 60px;}
      .pos4 { position: absolute;
              left: 20px;
              top: 120px;}
    </style>
  </head>
  <body >
    <p class="pos1" style="z-index: 2"><img
        src="images/ferrari.png" alt="A ferrari image">
    </p>
    <p class="pos2" style="z-index: 3"><img
        src="images/Trophy.png" alt="A Trophy image">
        The trophy is over the bulp and the ferrari</p>
    <p class="pos3" style="z-index: 1"><img
        src="images/bulb.png" alt="A bulb image">
        The bulp is under the ferrari and the trophy</p>
    <div><br/><br/><br/>
      This text will be beneath everything.</div>
    <div class="pos4"style="z-index: 4">
      This text will overlay all images.
    </div>
  </body>
</html>

Javascript access:

// To SET values ([o] is the target object)
[o].style.zIndex="z-index value"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:;
var value=cStyle.zIndex;
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.