CSS propertyTransforms

transform

Moves, rotates, scales, or skews an element without affecting the page layout.

Initial value
none
Inherited
No
Animatable
yes, as a transform
Applies to
transformable elements (not non-replaced inline elements)
JavaScript
element.style.transform = "rotate(10deg)"
On this page

Example

#
CSS
.card {
  transition: transform 0.2s;
}

.card:hover {
  transform: translateY(-4px) scale(1.02);
}
Preview

Definition and usage

#

The transform property changes an element’s appearance using functions: translate() moves, rotate() rotates, scale() scales, and skew() skews. Functions can be combined, and they are applied from right to left relative to the transform-origin point.

A transform does not affect layout: the element visually moves or grows, but its original space stays reserved and its neighbours don’t shift. That makes transforms great for animation.

Browsers animate transform very efficiently, usually on the GPU. Moving an element with transform: translate() is smoother than changing left or margin.

Syntax

#
Syntax
transform: none | <transform-function>+;

Values

#

Values in practice

#

none

No transform.
.demo { transform: none; }

translate(40px, -20px)

Moves 40px to the right and 20px up.
.demo { transform: translate(40px, -20px); }

rotate(25deg)

Rotates 25 degrees clockwise.
.demo { transform: rotate(25deg); }

scale(1.3)

Enlarges by 30%.
.demo { transform: scale(1.3); }

skew(-15deg)

Skews horizontally.
.demo { transform: skew(-15deg); }

rotate(15deg) scale(1.2)

Rotation and enlargement at the same time.
.demo { transform: rotate(15deg) scale(1.2); }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Use transform instead of top, left, or margin to animate movement. The browser then doesn’t have to recalculate layout.
  • The order of functions matters: rotate(45deg) translateX(50px) gives a different result than translateX(50px) rotate(45deg).

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.