CSS propertyTransforms

perspective

Adds depth to the 3D transforms of an element’s children.

Initial value
none
Inherited
No
Animatable
yes, as a length
Applies to
transformable elements (the effect applies to their children)
JavaScript
element.style.perspective = "600px"
On this page

Example

#
CSS
.scene {
  perspective: 700px;
}

.card {
  transform: rotateX(20deg) rotateY(-20deg);
}
Preview

Definition and usage

#

The perspective property is set on the parent. It defines how far from the screen the viewer’s eye is. Children rotated in 3D then look realistic: the nearer edge is larger and the farther one smaller.

A small value, for example 200px, gives a strong, dramatic perspective, as if viewing the element up close. A large value, for example 1500px, gives a subtle effect. none turns perspective off and 3D rotations look flat.

You can also set perspective for a single element with the perspective() function in its own transform.

Syntax

#
Syntax
perspective: none | <length>;

Values

#
  • none

    No depth: the rotated element looks flat.
  • 800px

    Moderate perspective.
  • 250px

    Strong perspective, as if seen up close.

Values in practice

#

none

No depth: the rotated element looks flat.
.scene { perspective: none; }

800px

Moderate perspective.
.scene { perspective: 800px; }

250px

Strong perspective, as if seen up close.
.scene { perspective: 250px; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • You set perspective on the parent and the rotation on the child. The other way round it won’t work.
  • Start with a value of 600-1000px, which looks natural in most interfaces.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.