perspective

  • Revision slug: CSS/perspective
  • Revision title: perspective
  • Revision id: 363643
  • Created:
  • Creator: oncletom
  • Is current revision? No
  • Comment Made example working for Webkit and IE10

Revision Content

{{ CSSRef() }}

{{ SeeCompatTable() }}

Summary

The perspective CSS property determines the distance between the z=0 plane and the user in order to give to the 3D-positioned element some perspective. Each 3D element with z>0 becomes larger; each 3D-element with z<0 becomes smaller. The strength of the effect is determined by the value of this property.

Part of the 3D-elements that are behind the user, i.e. that their z-axis coordinate is greater than the value of the perspective CSS property are not drawn.

The vanishing point is by default placed at the center of the element, but its position can be changed using the {{ cssxref("perspective-origin") }} property.

Using this property with a value different than 0 and none creates a new stacking context.

{{cssbox("perspective")}}

Syntax

Formal syntax: {{csssyntax("perspective")}}
perspective: none
perspective: 20px     /* <length> values */
perspective: 3.5em

perspective: inherited

Values

none
Is a keyword indicating that no perspective transform has to be applied.
<length>
Is a {{ xref_csslength() }} giving the distance from the user to the z=0 plane. It is used to apply a perspective transform to the element and its content. If it 0 or a negative value, no perspective transform is applied.

Examples

perspective:250px; perspective:350px; perspective:500px;
   
1
2
3
4
5
6
   
1
2
3
4
5
6
   
1
2
3
4
5
6

Specifications

Specification Status Comment
{{ Specname('CSS3 Transforms', '#perspective', 'perspective') }} {{ Spec2('CSS3 Transforms') }}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 12{{ property_prefix('-webkit') }} {{ CompatGeckoDesktop("10") }}{{ property_prefix('-moz') }}
{{ CompatGeckoDesktop("16") }}
10 {{ CompatNo() }} {{ CompatVersionUnknown() }}{{ property_prefix('-webkit') }}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 3.0{{ property_prefix('-webkit') }} {{ CompatGeckoMobile("10") }}{{ property_prefix('-moz') }}
{{ CompatGeckoMobile("16") }}
{{ CompatUnknown() }} {{ CompatNo() }} {{ CompatVersionUnknown() }}{{ property_prefix('-webkit') }}

See also

Revision Source

<p>{{ CSSRef() }}</p>
<p>{{ SeeCompatTable() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>perspective</code> <a href="/en/CSS" title="CSS">CSS</a> property determines the distance between the z=0 plane and the user in order to give to the 3D-positioned element some perspective. Each 3D element with z&gt;0 becomes larger; each 3D-element with z&lt;0 becomes smaller. The strength of the effect is determined by the value of this property.</p>
<p>Part of the 3D-elements that are behind the user, i.e. that their z-axis coordinate is greater than the value of the <code>perspective</code> CSS property are not drawn.</p>
<p>The <em>vanishing point</em> is by default placed at the center of the element, but its position can be changed using the {{ cssxref("perspective-origin") }} property.</p>
<p>Using this property with a value different than <code>0</code> and <code>none</code> creates a new <a href="/en/CSS/Understanding_z-index/The_stacking_context" title="en/CSS/Understanding_z-index/The_stacking_context">stacking context</a>.</p>
<p>{{cssbox("perspective")}}</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="twopartsyntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("perspective")}}</pre>
<pre>
perspective: none
perspective: 20px     /* &lt;length&gt; values */
perspective: 3.5em

perspective: inherited
</pre>
<h3 id="Values">Values</h3>
<dl>
  <dt>
    <code>none</code></dt>
  <dd>
    Is a keyword indicating that no perspective transform has to be applied.</dd>
  <dt>
    <code>&lt;length&gt;</code></dt>
  <dd>
    Is a {{ xref_csslength() }} giving the distance from the user to the z=0 plane. It is used to apply a perspective transform to the element and its content. If it <code>0</code> or a negative value, no perspective transform is applied.</dd>
</dl>
<h2 id="Examples" name="Examples">Examples</h2>
<div>
  <table class="standard-table">
    <tbody>
      <tr>
        <td><code>perspective:250px;</code></td>
        <td><code>perspective:350px;</code></td>
        <td><code>perspective:500px;</code></td>
      </tr>
      <tr>
        <td>
          <div class="container" style="width:200px;height:200px;margin:75px 0 0 75px;border:none;">
            <div class="cube" style="width:100%;height:100%;-moz-perspective:250px;-moz-transform-style:preserve-3d;-moz-perspective-origin:150% 150%;-webkit-perspective:250px; -webkit-transform-style:preserve-3d;-webkit-perspective-origin:150% 150%;perspective:250px; transform-style:preserve-3d;perspective-origin:150% 150%">
              <div class="middle" style="display: block;position: absolute;width: 100px;height: 100px;border: 1px dashed black;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: transparent;">
                &nbsp; &nbsp;</div>
              <div class="front" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba(   0, 0, 0, 0.3 );-moz-transform: translateZ( 50px ); -webkit-transform: translateZ( 50px ); transform: translateZ( 50px )">
                1</div>
              <div class="back" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba(   0, 255,   0, 1 ); color: black;-moz-transform: translateZ( -50px ); -webkit-transform: translateZ( -50px ); transform: translateZ( -50px );">
                2</div>
              <div class="right" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba( 196,   0,   0, 0.7 );-moz-transform: rotateY( 90deg) translateZ( 50px );-webkit-transform: rotateY( 90deg) translateZ( 50px );transform: rotateY( 90deg) translateZ( 50px );">
                3</div>
              <div class="left" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba(   0,   0, 196, 0.7 );-moz-transform: rotateY(-90deg) translateZ( 50px );-webkit-transform: rotateY(-90deg) translateZ( 50px );transform: rotateY(-90deg) translateZ( 50px );">
                4</div>
              <div class="top" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba( 196, 196,   0, 0.7 );-moz-transform: rotateX( 90deg) translateZ( 50px );-webkit-transform: rotateX( 90deg) translateZ( 50px );transform: rotateX( 90deg) translateZ( 50px );">
                5</div>
              <div class="bottom" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba( 196,   0, 196, 0.7);-moz-transform: rotateX(-90deg) translateZ( 50px );-webkit-transform: rotateX(-90deg) translateZ( 50px );transform: rotateX(-90deg) translateZ( 50px );">
                6</div>
            </div>
          </div>
        </td>
        <td>
          <div class="container" style="width:200px;height:200px;margin:75px 0 0 75px;border:none;">
            <div class="cube" style="width:100%;height:100%;-moz-perspective:350px;-moz-transform-style:preserve-3d;-moz-perspective-origin:150% 150%;-webkit-perspective:350px; -webkit-transform-style:preserve-3d;-webkit-perspective-origin:150% 150%;perspective:350px; transform-style:preserve-3d;perspective-origin:150% 150%">
              <div class="middle" style="display: block;position: absolute;width: 100px;height: 100px;border: 1px dashed black;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: transparent;">
                &nbsp; &nbsp;</div>
              <div class="front" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba(   0, 0, 0, 0.3 );-moz-transform: translateZ( 50px );-webkit-transform: translateZ( 50px );transform: translateZ( 50px );">
                1</div>
              <div class="back" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba(   0, 255,   0, 1 ); color: black;-moz-transform: translateZ( -50px );-webkit-transform: translateZ( -50px );transform: translateZ( -50px );">
                2</div>
              <div class="right" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba( 196,   0,   0, 0.7 );-moz-transform: rotateY( 90deg) translateZ( 50px );-webkit-transform: rotateY( 90deg) translateZ( 50px );transform: rotateY( 90deg) translateZ( 50px );">
                3</div>
              <div class="left" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba(   0,   0, 196, 0.7 );-moz-transform: rotateY(-90deg) translateZ( 50px );-webkit-transform: rotateY(-90deg) translateZ( 50px );transform: rotateY(-90deg) translateZ( 50px );">
                4</div>
              <div class="top" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba( 196, 196,   0, 0.7 );-moz-transform: rotateX( 90deg) translateZ( 50px );-webkit-transform: rotateX( 90deg) translateZ( 50px );transform: rotateX( 90deg) translateZ( 50px );">
                5</div>
              <div class="bottom" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba( 196,   0, 196, 0.7);-moz-transform: rotateX(-90deg) translateZ( 50px );-webkit-transform: rotateX(-90deg) translateZ( 50px );transform: rotateX(-90deg) translateZ( 50px );">
                6</div>
            </div>
          </div>
        </td>
        <td>
          <div class="container" style="width:200px;height:200px;margin:75px 0 0 75px;border:none;">
            <div class="cube" style="width:100%;height:100%;-moz-perspective:500px;-moz-transform-style:preserve-3d;-moz-perspective-origin:150% 150%;-webkit-perspective:500px; -webkit-transform-style:preserve-3d;-webkit-perspective-origin:150% 150%;perspective:500px; transform-style:preserve-3d;perspective-origin:150% 150%">
              <div class="middle" style="display: block;position: absolute;width: 100px;height: 100px;border: 1px dashed black;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: transparent;">
                &nbsp; &nbsp;</div>
              <div class="front" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba(   0, 0, 0, 0.3 );-moz-transform: translateZ( 50px );-webkit-transform: translateZ( 50px );transform: translateZ( 50px );">
                1</div>
              <div class="back" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba(   0, 255,   0, 1 ); color: black;-moz-transform: translateZ( -50px );-webkit-transform: translateZ( -50px );transform: translateZ( -50px );">
                2</div>
              <div class="right" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba( 196,   0,   0, 0.7 );-moz-transform: rotateY( 90deg) translateZ( 50px );-webkit-transform: rotateY( 90deg) translateZ( 50px );transform: rotateY( 90deg) translateZ( 50px );">
                3</div>
              <div class="left" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba(   0,   0, 196, 0.7 );-moz-transform: rotateY(-90deg) translateZ( 50px );-webkit-transform: rotateY(-90deg) translateZ( 50px );transform: rotateY(-90deg) translateZ( 50px );">
                4</div>
              <div class="top" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba( 196, 196,   0, 0.7 );-moz-transform: rotateX( 90deg) translateZ( 50px );-webkit-transform: rotateX( 90deg) translateZ( 50px );transform: rotateX( 90deg) translateZ( 50px );">
                5</div>
              <div class="bottom" style="display: block;position: absolute;width: 100px;height: 100px;border: none;line-height: 100px;font-family: arial, sans-serif;font-size: 60px;color: white;text-align: center;background: rgba( 196,   0, 196, 0.7);-moz-transform: rotateX(-90deg) translateZ( 50px );-webkit-transform: rotateX(-90deg) translateZ( 50px );transform: rotateX(-90deg) translateZ( 50px );">
                6</div>
            </div>
          </div>
        </td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="Specifications" name="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 Transforms', '#perspective', 'perspective') }}</td>
      <td>{{ Spec2('CSS3 Transforms') }}</td>
      <td>&nbsp;</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 (WebKit)</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>12{{ property_prefix('-webkit') }}</td>
        <td>{{ CompatGeckoDesktop("10") }}{{ property_prefix('-moz') }}<br />
          {{ CompatGeckoDesktop("16") }}</td>
        <td>10</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatVersionUnknown() }}{{ property_prefix('-webkit') }}</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&nbsp;Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>3.0{{ property_prefix('-webkit') }}</td>
        <td>{{ CompatGeckoMobile("10") }}{{ property_prefix('-moz') }}<br />
          {{ CompatGeckoMobile("16") }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatVersionUnknown() }}{{ property_prefix('-webkit') }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/CSS/Using_CSS_transforms" title="/en-US/docs/CSS/Using_CSS_transforms">Using CSS Transforms</a></li>
  <li>{{ CSS_Reference:Transforms() }}</li>
</ul>
Revert to this revision