DocsJavaScriptMotion reference

3D transforms and perspective

How the z axis, perspective and preserve-3d work on the web, and how to animate them with Motion.

Web pages are typically thought of two-dimensional pages. In most ways, this is true: Elements are infinitely thin 2D planes with layout rules that also only consider x and y axes.

However, CSS transforms do have the concept of 3D space. With transforms, elements can be translated and rotated, yes on the conventional x and y axes, but also along the z axis, with the visual effect of pushing an element into, or pulling it out of, the screen.

In this guide, we'll take a look at 3D transforms and perspective, and how we can use those to build flipping and tilting animations.

The three axes

CSS coordinates are slightly different from the graph paper you might remember from school. The 0, 0 origin point is in the screen's top-left corner. Positive x runs across the top, while positive y runs down the left.

You can visualise the 0 point of the z axis as anywhere on the screen, with positive values coming towards you and negative values going deeper "into" the screen.

PAGE COORDINATE SYSTEM0, 00xyz100-1003D TRANSFORMSFIG.01

Rotations

Rotating using a CSS rotate function will rotate an element in the intuitive way, in 2D space, like a clock.

ROTATE ON THE SCREEN PLANE