Skip to main content

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).

{{EmbedGHLiveSample("css-examples/modules/transforms.html", '100%', 900)}}

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

  • {{cssxref("backface-visibility")}}
  • {{cssxref("perspective")}}
  • {{cssxref("perspective-origin")}}
  • {{cssxref("rotate")}}
  • {{cssxref("scale")}}
  • {{cssxref("transform")}}
  • {{cssxref("transform-box")}}
  • {{cssxref("transform-origin")}}
  • {{cssxref("transform-style")}}
  • {{cssxref("translate")}}

Functions

  • {{cssxref("transform-function/matrix", "matrix()")}}
  • {{cssxref("transform-function/matrix3d", "matrix3d()")}}
  • {{cssxref("transform-function/perspective", "perspective()")}}
  • {{cssxref("transform-function/rotate", "rotate()")}}
  • {{cssxref("transform-function/rotate3d", "rotate3d()")}}
  • {{cssxref("transform-function/rotateX", "rotateX()")}}
  • {{cssxref("transform-function/rotateY", "rotateY()")}}
  • {{cssxref("transform-function/rotateZ", "rotateZ()")}}
  • {{cssxref("transform-function/scale", "scale()")}}
  • {{cssxref("transform-function/scale3d", "scale3d()")}}
  • {{cssxref("transform-function/scaleX", "scaleX()")}}
  • {{cssxref("transform-function/scaleY", "scaleY()")}}
  • {{cssxref("transform-function/scaleZ", "scaleZ()")}}
  • {{cssxref("transform-function/skew", "skew()")}}
  • {{cssxref("transform-function/skewX", "skewX()")}}
  • {{cssxref("transform-function/skewY", "skewY()")}}
  • {{cssxref("transform-function/translate", "translate()")}}
  • {{cssxref("transform-function/translate3d", "translate()")}}
  • {{cssxref("transform-function/translateX", "translateX()")}}
  • {{cssxref("transform-function/translateY", "translateY()")}}
  • {{cssxref("transform-function/translateZ", "translateZ()")}}

Data types

  • {{cssxref("<transform-function>")}}

Guides

Specifications

See also