Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Functions

Transform functions: translate(), rotate(), scale() and more

Reference for CSS transform functions: translate, rotate, scale, skew, matrix and perspective, with arguments, order of operations and live examples.

Transform functions are the values you pass to the transform property. Each one describes a geometric change to an element's box: move it, turn it, resize it, slant it. The element is changed visually only; its layout space stays where it was, and neighbors do not move.

You can list several functions in one transform. They are applied one after another, and the order matters.

CSS
.card {
  transform: translate(20px, 10px) rotate(8deg) scale(1.1);
}

Try it

The basic functions
Order matters

Syntax

CSS
/* 2D */
translate(x)  translate(x, y)  translateX(x)  translateY(y)
rotate(angle)
scale(s)  scale(sx, sy)  scaleX(sx)  scaleY(sy)
skew(ax)  skew(ax, ay)  skewX(ax)  skewY(ay)
matrix(a, b, c, d, tx, ty)

/* 3D */
translateZ(z)  translate3d(x, y, z)
rotateX(angle)  rotateY(angle)  rotateZ(angle)  rotate3d(x, y, z, angle)
scaleZ(sz)  scale3d(sx, sy, sz)
matrix3d(/* 16 numbers */)
perspective(length)

These functions are values of transform. The same movements are also available as the standalone properties translate, rotate and scale.

Values

Function Description
translate(x, y) Moves the element. Lengths or percentages; a percentage is relative to the element's own box. If y is omitted it is 0.
rotate(angle) Rotates clockwise around the transform origin. Units: deg, rad, grad, turn. Negative angles turn counter-clockwise.
scale(sx, sy) Multiplies size by plain numbers. 1 means unchanged, 0.5 half size, -1 mirrors. One value scales both axes.
skew(ax, ay) Slants the element by angles. skewX shears horizontally, skewY vertically. There is no 3D skew.
matrix(a, b, c, d, tx, ty) All 2D effects in six numbers. Powerful, but hard to read; prefer named functions.
rotateX/Y/Z, translateZ, scaleZ, *3d 3D versions. They look flat unless a perspective is set.
perspective(length) Adds depth for the element's own transform. It must come first in the list to affect the functions after it.

Usage notes

  • Order. Each function works in the coordinate system left by the previous one (see the second example). Writing rotate() before translate() moves along the rotated axes.
  • The origin. Rotation, scale and skew pivot around transform-origin, which defaults to the center of the box.
  • Percentages. translate(50%, 50%) moves by half of the element's own width and height, which is why translate(-50%, -50%) centers an absolutely positioned box.
  • Replaces, does not add. Declaring transform again replaces the whole list. Use the individual translate, rotate and scale properties when you need to animate them independently.
  • Performance. Animating transform is usually smooth because it can run on the compositor without recalculating layout.
  • Side effects. A transform creates a stacking context and a containing block for fixed-position descendants.
  • Inline elements cannot be transformed; make them inline-block or give them another display value.

Browser support

The 2D functions work everywhere. The 3D functions are widely supported; the standalone translate, rotate and scale properties are newer, so check a compatibility table for them.