Revision Content

By modifying the coordinate space, CSS transforms allow to change the position and shape of the affected content without disrupting the normal document flow. This guide provides an introduction to using transforms.

CSS transforms are implemented using a set of CSS properties that let you apply affine linear transformations to HTML elements. These transformations include rotation, skewing, scaling, and translation both in the plane and in the 3D space.

CSS transforms properties

Two major properties are used to define CSS transforms: {{ cssxref("transform") }} and {{ cssxref("transform-origin") }}

{{ cssxref("transform-origin") }}

Specifies the position of the origin. By default it is at the center of the element and can be moved. It is used by several transforms, like rotations, scaling or skewing, that need a specific point as parameter.

{{ cssxref("transform") }}

Specifies the transforms to apply to the element. It is a space separated list of transform, which are applied one after the other, like requested by the composition operation.

Examples

Example: Rotating

This example creates an iframe that lets you use Google's home page, rotated 90 degrees about its bottom-left corner.

3D specific CSS properties

Performing CSS transformations in the space is a little bit more complex. You have to start by configuring the 3D space by giving it a perspective, then you have to configure how your 2D elements will behave in that space.

Setting up a perspective

The first element to set is the perspective. The perspective is what gives the 3D impression. The farther from the viewer the elements are, the smaller there are.

How quick they shrink is defined by the {{ cssxref("perspective") }} property. The smaller its value is, the deeper the perspective is.

perspective:0;

perspective:250px;

1

2

3

4

5

6

1

2

3

4

5

6

perspective:300px;

perspective:350px;

1

2

3

4

5

6

1

2

3

4

5

6

The second element to configure is the position of the viewer, with the {{ cssxref("perspective-origin") }} property. By default, the perspective is centered on the viewer, which is not always adequate.