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.
.scene { perspective: 600px; } .card { transform: rotateY(40deg); }
Try it
Syntax
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.
perspectiveaffects the children of the element that has it. To give an element's own transform perspective, use theperspective()function at the start of itstransformlist (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 hastransform-style: preserve-3d. - Side effects. A value other than
nonecreates a stacking context and a containing block for fixed and absolute descendants. - Values under about
100pxpush objects past the viewer and cause extreme distortion; typical values are500pxto1200px. - Pairs with
backface-visibilityfor flip cards.
Browser support
Supported in every current browser.