CSS propertyTransforms
perspective-origin
Sets the point from which the viewer looks at a 3D scene.
- Initial value
50% 50%- Inherited
- No
- Animatable
- yes, as a length or percentage
- Applies to
- transformable elements (the effect applies to their children)
- JavaScript
element.style.perspectiveOrigin = "left top"
Example
#CSS
.stairs {
perspective: 500px;
perspective-origin: 50% -50%;
}Example HTML
<div class="stairs" style="perspective: 500px; perspective-origin: 50% -50%; display: grid; gap: 6px; padding: 16px;">
<div class="box" style="transform: rotateX(40deg);">Level 3</div>
<div class="box" style="transform: rotateX(40deg);">Level 2</div>
<div class="box" style="transform: rotateX(40deg);">Level 1</div>
</div>Preview
Definition and usage
#The perspective-origin property moves the perspective vanishing point. By default the viewer looks exactly at the centre of the element. Moving the point makes the scene look as if viewed from above, from the side, or from below.
It works together with perspective and, like it, is set on the parent while affecting the appearance of children transformed in 3D.
It accepts keywords, percentages, and lengths, just like transform-origin.
Syntax
#Syntax
perspective-origin: <x> <y>?;Values
#Values in practice
#center
The viewer looks at the centre of the scene.
.scene { perspective-origin: center; }top
A view from above.
.scene { perspective-origin: top; }bottom
A view from below.
.scene { perspective-origin: bottom; }left
A view from the left side.
.scene { perspective-origin: left; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Without
perspectiveset, this property changes nothing. - A slight shift of the vanishing point adds realism to 3D scenes, because we rarely look at something perfectly head-on.
Related entries
#Spotted a mistake or missing an example? Write to us.