Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Transforms, Transitions and Animations

The perspective property

Reference for the CSS perspective property: give child elements 3D depth by setting the viewing distance, and see how it differs from the perspective() function.

The perspective property gives the children of an element a sense of depth when they are transformed in 3D. Its value is the distance between the viewer and the plane z = 0: a small distance such as 200px gives strong, dramatic foreshortening, while a large one like 1500px looks nearly flat.

Without it, a 3D rotation such as rotateY(60deg) just squashes the element horizontally, because there is no vanishing point. The vanishing point defaults to the center of the element and can be moved with perspective-origin.

CSS
.scene {
  perspective: 600px;
}
.card {
  transform: rotateY(40deg);
}

Try it

Perspective distance

Syntax

CSS
perspective: none | <length [0,โˆž]>;
  • Initial value: none
  • Applies to: transformable elements
  • Inherited: no
  • Animatable: yes, as a length
  • Computed value: none, or an absolute length

Values

Value Description
none No perspective is applied. Also the effect of 0.
<length> The distance from the viewer to the z=0 plane. Lower values mean stronger distortion. Negative values are invalid.

Usage notes

  • Put it on the parent. perspective affects the children of the element that has it. To give an element's own transform perspective, use the perspective() function at the start of its transform list (transform: perspective(500px) rotateY(40deg)).
  • One scene, one vanishing point. With the property on a shared parent, all children share the same vanishing point, which looks like one coherent scene. Using the function on each child gives every child its own.
  • Deeper nesting needs preserve-3d. Grandchildren take part in the scene only if every parent in between has transform-style: preserve-3d.
  • Side effects. A value other than none creates a stacking context and a containing block for fixed and absolute descendants.
  • Values under about 100px push objects past the viewer and cause extreme distortion; typical values are 500px to 1200px.
  • Pairs with backface-visibility for flip cards.

Browser support

Supported in every current browser.