Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

CSS transform generator

Move, rotate, scale and skew a box with sliders and copy the result. The default shows `translate(40px, 20px) rotate(30deg) scale(1.2)`, which is the same as `matrix(1.0392, 0.6, -0.6, 1.0392, 40, 20)`, and the page works out where the box lands.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Box
3D: rotate X, rotate Y and perspective
CSS
transform: translate(40px, 20px) rotate(30deg) scale(1.2);
  • Order: move first
The same transform as a matrix
matrix(1.0392, 0.6, -0.6, 1.0392, 40, 20)
Center of the box lands at
90, 70
Top left corner lands at
68.0385, -11.9615

Points are in pixels on a 100 px box, measured from the box's own top left corner before the transform. Changing the order of the steps changes where the box ends up.

How to use the CSS Transform Generator

  1. Drag a slider or type a value for Move, Rotate, Scale or Skew. The box in the preview follows at once.
  2. Pick the Transform origin and the Order in the list, and open the 3D part for rotate X, rotate Y and perspective.
  3. Press Copy CSS to copy the declaration, with the origin line when it is not the center.
  4. Read the matrix form and the point where the center and the top left corner of a 100 px box land.

How does the CSS transform property work?

The `transform` property takes a list of steps such as translate, rotate, scale and skew. A step that does nothing has no effect, so this page leaves it out: a move of 0 px, a rotation of 0 degrees or a scale of 100% never shows up in the CSS. The default values give `translate(40px, 20px) rotate(30deg) scale(1.2)`.

The whole list can be written as one matrix, six numbers in the form matrix(a, b, c, d, e, f). For the default list the page gets `matrix(1.0392, 0.6, -0.6, 1.0392, 40, 20)`. The numbers a, b, c and d carry the rotation and the scale: 1.2 times the cosine of 30 degrees is 1.0392, and 1.2 times the sine is 0.6. The last two numbers, 40 and 20, are the move in pixels.

Skew works through the tangent of the angle. A skew of 20 degrees across gives `matrix(1, 0, 0.364, 1, 0, 0)`, where 0.364 is the tangent of 20 degrees, and a second skew of 10 degrees down adds the tangent of 10 degrees, 0.1763, to b: `matrix(1, 0.1763, 0.364, 1, 0, 0)`. Copy the matrix when you need it in another tool, or the list when you want CSS that is easy to read.

Does the order of the transform functions matter?

Yes. The steps are combined in the order written, and each one works in the space left by the one before it. A move written before a rotation shifts the box along the page axes. A move written after the rotation shifts it along the rotated axes. The page offers both through the Order field, and the table shows the same three steps in each order.

For the default values the first order ends with a shift of 40 and 20 pixels in the matrix. The second order ends with 29.5692, 44.7846, because the 40 and 20 pixel move is turned by 30 degrees and stretched by 1.2 along the way. The box center lands at 90, 70 in the first order and at 79.5692, 94.7846 in the second, measured on a 100 px box.

Rotation and scale also depend on each other when the scale differs across and down. Written rotate(45deg) scale(2, 1), the stretch follows the rotated axes and the third matrix number is -0.7071. Written scale(2, 1) rotate(45deg), the stretch follows the page axes and the third number is -1.4142.

The same three steps in two orders
CSSOrderMatrix
translate(40px, 20px) rotate(30deg) scale(1.2)Move firstmatrix(1.0392, 0.6, -0.6, 1.0392, 40, 20)
rotate(30deg) scale(1.2) translate(40px, 20px)Move lastmatrix(1.0392, 0.6, -0.6, 1.0392, 29.5692, 44.7846)

What does transform-origin change?

The origin is the point the rotation, scale and skew work around. It is the center of the box by default. Move it to a corner and the box swings around that corner instead. The numbers in the table come from a 100 px box rotated 45 degrees with no move or scale, and they show where the center of the box and its top left corner end up.

With the center as the origin, the center stays at 50, 50 and the corner swings to 50, -20.7107. With the origin at the top left, the corner stays at 0, 0 and the center swings down to 0, 70.7107. The page writes a `transform-origin` line only when you leave the center.

Rotate X, rotate Y and perspective make the box turn in depth. Perspective is a length in pixels, and the preview shows what each value does. These steps have no 2D matrix, so the matrix line says so and the CSS still comes out.

Where a 100 px box lands after rotate(45deg)
OriginCenter of the boxTop left corner
center50, 5050, -20.7107
top left0, 70.71070, 0
top right29.2893, 029.2893, -70.7107
bottom left70.7107, 10070.7107, 29.2893
bottom right100, 29.2893100, -41.4214

Use it with

Questions

How do I rotate an element with CSS?

Set the rotate step in the transform property, for example transform: rotate(30deg);. Drag the Rotate slider and the preview shows the direction of the turn.

What is the order of CSS transforms?

The steps combine in the order written, each in the space left by the one before. Move then rotate is not the same as rotate then move: for the default values the matrices end in 40, 20 and 29.5692, 44.7846.

What does the matrix mean?

It holds the same transform as six numbers, matrix(a, b, c, d, e, f). The first four carry rotation, scale and skew, and the last two are the move in pixels.

How do I rotate around a corner?

Choose a corner in Transform origin. The page adds a transform-origin line, and a box rotated 45 degrees about its top left corner keeps that corner at 0, 0.

What is the default transform origin?

The center of the element. The page leaves the transform-origin line out when the origin is the center.

Does the page keep my values?

No. They stay in your browser and the page saves nothing.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.