mozilla

Revision 357565 of z-index

  • Revision slug: CSS/z-index
  • Revision title: z-index
  • Revision id: 357565
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

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}} {{cssinitial("z-index")}}
  • Applies to {{Cssxref("position", "positioned elements")}}
  • {{Xref_cssinherited}} no
  • Media {{Xref_cssvisual}}
  • {{Xref_csscomputed}} as specified

Syntax

Formal syntax: {{csssyntax("z-index")}}
z-index: auto     /* Keyword value */
z-index: 0        /* <integer> value */
z-index: 3
z-index: 289

z-index: 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:2; left:60px; top:3em; position:absolute; z-index:3;
left:20em; top:-25px; opacity:0.9

Specifications

Specification Status Comment
{{SpecName('CSS3 Transitions', '#animatable-css', 'visibility')}} {{Spec2('CSS3 Transitions')}} Defines visibility as animatable.
{{SpecName('CSS2.1', 'visuren.html#z-index', 'z-index')}} {{Spec2('CSS2.1')}} Initial specification.

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1.0")}} 4.0 4.0 1.0
Negative values (CSS2.1 behavior, not allowed in the obsolete CSS2 spec) 1.0 {{CompatGeckoDesktop("1.9")}} 4.0 4.0 1.0
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

See also

Revision Source

<div>
  {{CSSRef}}</div>
<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> {{cssinitial("z-index")}}</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 class="twopartsyntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("z-index")}}
</pre>
<pre>
z-index: auto     /* Keyword value */
z-index: 0        /* &lt;integer&gt; value */
z-index: 3
z-index: 289

z-index: inherit
</pre>
<h3 id="Values">Values</h3>
<dl>
  <dt>
    <code>auto</code></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>
    <code>&lt;integer&gt;</code></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;margin-top: 2em;">
  position:relative; z-index:1; <span style="background:gold; position:absolute; z-index:2; left:60px; top:3em; ">position:absolute; z-index:2; left:60px; top:3em;</span> <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></div>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{SpecName('CSS3 Transitions', '#animatable-css', 'visibility')}}</td>
      <td>{{Spec2('CSS3 Transitions')}}</td>
      <td>Defines <code>visibility</code> as animatable.</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS2.1', 'visuren.html#z-index', 'z-index')}}</td>
      <td>{{Spec2('CSS2.1')}}</td>
      <td>Initial specification.</td>
    </tr>
  </tbody>
</table>
<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.0")}}</td>
        <td>4.0</td>
        <td>4.0</td>
        <td>1.0</td>
      </tr>
      <tr>
        <td>Negative values (CSS2.1 behavior, not allowed in the obsolete CSS2 spec)</td>
        <td>1.0</td>
        <td>{{CompatGeckoDesktop("1.9")}}</td>
        <td>4.0</td>
        <td>4.0</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>
<h2 id="See_also">See also</h2>
<ul>
  <li>CSS {{Cssxref("position")}} property</li>
  <li><a href="/en-US/docs/CSS/Understanding_z-index" title="CSS/Understanding_z-index">Understanding CSS z-indexes</a></li>
</ul>
Revert to this revision