CSS transforms

The CSS transforms module defines how elements styled with CSS can be transformed in two-dimensional or three-dimensional space.

CSS transforms in action

Use the sliders in the frame below to modify the translation, rotation, scale, and skew CSS transform properties of the cube in 3D space. As you move the cube through 3D space, notice the way it interacts with the element labelled z:0px, which is located at the 3D position (0, 0, 0).

You can also use the perspective slider to modify the perspective property of the cube's container, which determines the distance between you and the z=0 plane.

The perspective-origin sliders determine where you, the viewer, are looking into the 3D space for purposes of determining the view's vanishing point. This vanishing point is indicated by a small red dot. You can imagine modifying these sliders as physically moving your head up, down, left, and right to see different parts of the cube without moving the cube itself.

The backface-visibility checkbox determines whether the cube's back faces are set to visible or hidden.

The cube in the above example is comprised of six <div> elements, all of which are styled with CSS to create the cube's faces. The cube is not drawn using a 2D or 3D canvas context, so you can inspect the faces of the cube with your browser's developer tools as you would inspect any other DOM element. Try using your browser's developer tools element picker to inspect different faces of the cube as you transform its position and rotation.

Note: The order in which transformations, including 3D rotations, are applied affects the resultant transformation. In the above example, transforms are translated, scaled, rotated, then skewed. The rotations are applied in the order X → Y → Z.

You can view this example's source on GitHub.

Reference

Properties

Functions

Data types

Guides

Using CSS transforms

Step-by-step tutorial about how to transform elements styled with CSS.

Coordinate systems

Describes the way pixel locations are defined in the CSS object model.

Performance fundamentals: Use CSS transforms

An overview of web performance fundamentals, including how CSS transforms can improve performance.

Matrix math for the web

Describes how object transformations can be represented by mathematical matrices.

Specifications

Specification
CSS Transforms Module Level 1
CSS Transforms Module Level 2

See also