Transform

perspective

perspective sets how far away you are looking from when child elements are rotated or moved in 3D, giving them depth. The smaller the value, the closer you are: near parts look bigger and far parts smaller.

Syntax

none | <length [0,∞]>

Preview

3D
Presets
Drag the bottom-right corner to resize

Code

.box {
  perspective: 300px;
}

.box > :nth-child(2) {
  transform: rotateY(50deg);
}

Controls

perspective300px
3D

About

Values

  • none: the initial value. No depth is added; a child rotated on the vertical axis just looks narrower.
  • Length: the distance from the eye to the element's plane (depth 0). Small values like 100px distort strongly; large values like 1000px look almost flat. Negative values are not allowed, and values below 1px are drawn as 1px.

Things to watch

  • It affects the 3D transforms of the element's children (and of descendants still drawn in 3D), not the element's own transform. To give a single element depth, put the perspective() function first, as in transform: perspective(300px) rotateY(50deg).
  • Where you look from (the vanishing point) is set by perspective-origin. It defaults to the middle of the element.
  • Any value other than none creates a new stacking context and, like transform, makes position: fixed children position themselves against this element.

The preview stacks a dashed frame (the first child) and a card (the second child) in the box, and a supporting declaration turns the card 50 degrees on the vertical axis (transform: rotateY(50deg)).

Comments