Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Transforms, Transitions and Animations

The transform property

Reference for the CSS transform property: translate, rotate, scale, skew and 3D transform functions, how order matters, and how transforms affect layout and stacking.

The transform property moves, rotates, scales or skews an element, in two or three dimensions, without changing how the rest of the page is laid out. You give it a list of transform functions, and the browser applies them to the element's box around its transform-origin.

Transforms change only how the element is painted and where it responds to the pointer. Its original space in the layout stays reserved, so neighbors do not move. That, and the fact that browsers can animate transforms cheaply on the GPU, makes transform the standard tool for movement and hover effects.

CSS
.badge {
  transform: translate(10px, -5px) rotate(15deg) scale(1.2);
}

Try it

Common transform functions

The last two boxes use the same functions in different order and end up in different places. Each function works in the coordinate system left by the ones before it, so a rotation first means the following translation runs along the rotated axis.

Syntax

CSS
transform: none | <transform-function>+;
  • Initial value: none
  • Applies to: transformable elements (block-level and atomic inline-level boxes, most SVG elements; not plain inline text boxes)
  • Inherited: no
  • Animatable: yes (functions are interpolated pairwise when the lists match, otherwise via matrices)
  • Computed value: none, or the list of functions with lengths made absolute

Values

Value Description
translate(x, y), translateX(), translateY(), translateZ(), translate3d() Move the element. Percentages refer to the element's own size.
rotate(angle), rotateX(), rotateY(), rotateZ(), rotate3d() Rotate by an angle such as 45deg, 0.5turn or 1rad.
scale(x, y), scaleX(), scaleY(), scaleZ(), scale3d() Resize by a factor. 1 is unchanged, negative values mirror.
skew(ax, ay), skewX(), skewY() Slant the element along an axis by an angle.
matrix(), matrix3d() Full transformation matrix; mostly generated by tools.
perspective(length) Gives the element's own 3D transforms depth.
none No transform.

See translate() and friends for details on each function.

Usage notes

  • Order matters. Functions apply right to left in terms of coordinates, but it is easiest to read the list left to right as "each step moves the origin for the next".
  • Stacking and containing blocks. Any value other than none creates a new stacking context and becomes the containing block for fixed and absolute descendants. This can break position: fixed children unexpectedly.
  • Layout is unchanged. Transformed elements still occupy their original space, and scrollable overflow includes the transformed area on the end side.
  • Pointer hits follow the transform. Clicks and hover use the visual shape, which is why a scaled-up button grows its hit area too.
  • Blurry text. Fractional translations or scales can make text look soft; round values or avoid transforms on large text blocks.
  • Individual properties. translate, rotate and scale let you set or animate one effect without rewriting the whole list. They are applied before transform.
  • Inline elements such as a plain <span> ignore transforms until you give them display: inline-block or similar.
  • Accessibility. Respect prefers-reduced-motion when animating large movements.

Browser support

2D transforms are supported in every browser. 3D transforms are also widely supported. The separate translate, rotate and scale properties are newer; check a compatibility table if you target older browsers.