Skip to the page
css reference · interaction & polish

CSS transform

type
property
applies to
any element
inherits
no
common values
translateY(-2px), scale(1.05), rotate(45deg), translate(-50%, -50%)

Where it goes

On the box to move, usually in a :hover state with a transition on the normal rule. Several functions can be combined in one value: transform: translateY(-2px) scale(1.02).

Example

.card {
  transition: transform 150ms, box-shadow 150ms;
}
.card:hover { transform: translateY(-4px); }
.chev.open { transform: rotate(180deg); }
.modal {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

Common mistakes

  • Animating top, left or margin to move something. The browser recalculates the layout every frame and it stutters. Animate transform instead.
  • Expecting neighbors to move out of the way. They do not. transform is purely visual. If space must change, use margin or layout.
  • Scaling text up with transform and getting blur. transform scales the drawn pixels. For bigger text, change font-size.

Related

Updated 24 October 2026. Practice it in the css route, or read more on MDN.