z-index

  • Revision slug: CSS/z-index
  • Revision title: z-index
  • Revision id: 8465
  • Created:
  • Creator: tregagnon
  • Is current revision? No
  • Comment Remove unnecessary <nobr>; one or more formatting changes

Revision Content

{{ CSSRef() }}

Summary

The z-index CSS property specifies the z-order of an element and its descendants. When elements overlap, z-order determines which one covers the other. An element with a larger z-index generally covers an element with a lower one.

For a positioned box, the z-index property specifies:

  1. The stack level of the box in the current stacking context.
  2. Whether the box establishes a local stacking context.
  • {{ Xref_cssinitial() }}: {{ Cssxref("auto") }}
  • Applies to: {{ Cssxref("position", "positioned elements") }}
  • {{ Xref_cssinherited() }}: no
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

z-index:  auto | <integer> | inherit

Values

auto
The box does not establish a new local stacking context. The stack level of the generated box in the current stacking context is the same as its parent's box.
<integer>
This integer is the stack level of the generated box in the current stacking context. The box also establishes a local stacking context in which its stack level is 0. This means that the z-indexes of descendants are not compared to the z-indexes of elements outside this element.

Examples

position:relative; z-index:1; position:absolute; z-index:3;
left:20em; top:-25px; opacity:0.9
position:absolute; z-index:2; left:60px; top:3em;

Specifications

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{ CompatGeckoDesktop("1") }}

4.0

4.0

1.0
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

Gecko Notes

Negative z-index values are supported correctly starting in Gecko 1.9 / Firefox 3. Previous versions implemented the CSS 2 behavior, not the CSS 2.1 behavior that is compatible with other browsers.

See also

{{ languages( { "fr": "fr/CSS/z-index", "pl": "pl/CSS/z-index", "pt": "pt/CSS/z-index" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The<code> z-index </code>CSS property specifies the z-order of an element and its descendants. When elements overlap, z-order determines which one covers the other. An element with a larger z-index generally covers an element with a lower one.</p>
<p>For a positioned box, the<code> z-index </code>property specifies:</p>
<ol> <li>The stack level of the box in the current stacking context.</li> <li>Whether the box establishes a local stacking context.</li>
</ol>
<ul class="cssprop"> <li><dfn>{{ Xref_cssinitial() }}:</dfn> {{ Cssxref("auto") }}</li> <li><dfn>Applies to:</dfn> {{ Cssxref("position", "positioned elements") }}</li> <li><dfn>{{ Xref_cssinherited() }}:</dfn> no</li> <li><dfn>Media:</dfn> {{ Xref_cssvisual() }}</li> <li><dfn>{{ Xref_csscomputed() }}:</dfn> as specified</li>
</ul>
<h2 id="Syntax">Syntax</h2>
<pre>z-index:  auto | &lt;integer&gt; | inherit
</pre>
<h3 id="Values">Values</h3>
<dl> <dt>auto</dt> <dd>The box does not establish a new local stacking context. The stack level of the generated box in the current stacking context is the same as its parent's box.</dd> <dt>&lt;integer&gt;</dt> <dd>This integer is the stack level of the generated box in the current stacking context. The box also establishes a local stacking context in which its stack level is<code> 0</code>. This means that the z-indexes of descendants are not compared to the z-indexes of elements outside this element.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<div style="border:dashed; position:relative; z-index:1; height:8em; margin-bottom:1em">position:relative; z-index:1; <span style="background:lightgreen; position:absolute; z-index:3; left:20em; top:-25px; height:7em; opacity:0.9">position:absolute; z-index:3;<br> left:20em; top:-25px; opacity:0.9</span> <span style="background:gold; position:absolute; z-index:2; left:60px; top:3em; ">position:absolute; z-index:2; left:60px; top:3em;</span></div>
<h2 id="Specifications">Specifications</h2>
<ul> <li><a class="external" href="http://www.w3.org/TR/CSS21/visuren.html#z-index" title="http://www.w3.org/TR/CSS21/visuren.html#z-index">CSS 2.1 Visual formatting #z-index</a></li>
</ul>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>1.0</td> <td>{{ CompatGeckoDesktop("1") }}</td> <td> <p>4.0</p> </td> <td> <p>4.0</p> </td> <td>1.0</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Mobile</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody> </table>
</div>
<h3 id="Gecko_Notes">Gecko Notes</h3>
<p>Negative<code> z-index </code>values are supported correctly starting in <a href="/en/Gecko" title="en/Gecko">Gecko</a> 1.9 / <a href="/en/Firefox_3_for_developers" title="en/Firefox_3_for_developers">Firefox 3</a>. Previous versions implemented the CSS 2 behavior, not the CSS 2.1 behavior that is compatible with other browsers.</p>
<h2 id="See_also">See also</h2>
<ul> <li>CSS {{ Cssxref("position") }} property</li> <li><a href="/en/CSS/Understanding_z-index" title="en/CSS/Understanding_z-index">Understanding CSS z-indexes</a></li>
</ul>
<p>{{ languages( { "fr": "fr/CSS/z-index", "pl": "pl/CSS/z-index", "pt": "pt/CSS/z-index" } ) }}</p>
Revert to this revision