Perspective() - CSS Function

perspective()

Summary of characteristics of the perspective() function

Quick description
Sets the height of the observer in the case of a 3D transformation.
Status
Standard
Percentages
Not applicable.
W3C Module
CSS Transforms Module
Document status: WD (Working Draft)

Description of the perspective() function.

The function perspective() sets the distance between the observer and the element along the Z-axis. As long as the transformations happen in the plane of the screen (along the X-axis or Y-axis), perspective has no effect. But transformations that move the element along the Z-axis will be affected by perspective: if the element gets closer, it will appear bigger; if it moves away, it will shrink.

Reference framework for the perspective function()

Example: the three blocks below have identical dimensions. The first one is in the plane of the screen: its dimensions are unchanged; the second one has been moved back, using a negative value for translatez(); and the third one has been moved forward.
You'll notice that they all really do have the same dimensions. Their size difference is only due to their distance from the viewer.

translatez(0)
translatez(-100px)
translatez(100px)

There is also a property perspective that has a similar role, but with one difference: the property applies to the parent of the transformed element, whereas the function applies to the element itself, via the property transform.

The perspective() value can be used with the following properties:

  • transform : Applies one or more geometric transformations (rotations, enlargements, etc.).

Syntaxes of the perspective() function.

  • transform: perspective(200px); h

    h is a positive number followed by a unit of absolute dimension (See CSS dimension units).
    It defines the observer's height, in other words the distance between the observer and the next element along the Z axis. The smaller this number, the stronger the perspective effect.

Simulator.

The perspective effect is visible when a transformation moves an element out of the screen plane. The third block has been rotated around the Z axis: it stays in the screen plane, so the perspective() function has no effect on it.

transform :
rotateX(45deg)
rotateY(-45deg)
rotateZ(45deg)

Browsers compatibility with perspective() function.

All the common browsers handle 3D transformations correctly, as well as the perspective() function, which is essential for 3D rendering.

Column 1
General support for 3D animations, including support for perspective management and support for the backface-visibility property.
Column 2
Support for the function perspective() which allows for better visualization of the effects of a 3D transformation.

Notes:

(1) Internet Explorer does not support transform-style:preserve-3d, thus limiting the nesting of animations.

1
3D
transformations
2
perspective()
function
Estimated overall support.
97%
97%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Opéra

Firefox pour Androïd

Samsung Internet

Chrome

Edge

Firefox

Androïd Brower

Chrome pour Androïd

Baidu Browser

QQ Browser

Safari

Safari sur IOS

UC Browser pour Androïd

Opéra mini

Historic of the perspective() function.

  • CSS Transforms Module Level 2

    In addition to the 2D transformations already presented in level 1 of the specification, this module deals with 3D transformations. It introduces new properties to manage the viewpoint height and the rendering of 3D effects.
    This module also introduces the individual properties of rotation, translation, and zoom effect.

    Regarding perspective() Introduction of 3D transformations and the perspective() function in the specification.
    WD
    March 03, 2020
    Working Draft.
    CR
    PR
    REC

See also, about the transformations.

The specification module "CSS Transforms Module" gathers all the properties and functions concerning CSS transformations:

Properties:

backface-visibility
Visibility of the rear side of the element (while it is rotating).
perspective
A perspective effect applied to a 3D transformed element.
perspective-origin
Position of the observer in the case of a 3D distortion with perspective.
rotate
Defines a rotation to apply to the element.
scale
Sets a scaling of the element (magnification or shrinking).
transform
Applies one or more geometric transformations (rotations, enlargements, etc.).
transform-box
Sets the reference box for transformations.
transform-origin
Sets the origin point for transformations.
transform-style
Defines how elements that undergo a 3D transformation are rendered.
translate
Applies a translation to an element (a linear displacement).

Functions:

matrix()
Applies a composite transformation to an element (translations, rotations...).
matrix3d()
Applies a series of 3D transformations to an element.
Perspective()
Sets the height of the observer in the case of a 3D transformation.
rotate()
Sets a rotation to apply to the element in 2D (in the plane of the screen).
rotate3d()
Defines a 3D rotation to be applied to an element around any axis in 3D.
rotateX()
Defines a rotation of the element around the X-axis (in 3D),
rotateY()
Sets a 3D rotation of the element around the y-axis.
rotateZ()
Sets a rotation of the element around the z-axis.
scale()
Sets a magnification or reduction of the element.
scale3d()
Sets 3D scaling.
scaleX()
Sets X-axis scaling.
scaleY()
Set Y-axis scaling.
scaleZ()
Set Z-axis scaling.
skew()
Sets a tilt of the element along the X and/or Y axes.
skewX()
Sets a tilt of the element along the X-axis.
skewY()
Sets a tilt of the element along the Y-axis.
translate()
Defines a translation (a linear move) to an element.
translate3d()
Defines a 3D translation along one or more of the X, Y, and Z axes.
translateX()
Defines a translation along the X-axis (horizontally).
translateY()
Defines a translation along the Y axis (vertically).
translateZ()
Defines a translation along the Z axis (perpendicular to the screen).