rotate

Term side of the Card.
Topic: Transformations
Unit title: rotate
Categories: Property
Explanation side of the Card

Explanation: The property that applies a 2D or 3D rotation to an element around a fixed point. It doesn't overwrite the `transform` property, as it directly sets the rotation without affecting other transform functions. This property is useful for rotating elements to achieve various visual effects.

Browser compatibility:
  • The chrome browser supports this feature starting from version 104.
  • The edge browser supports this feature starting from version 104.
  • The firefox browser supports this feature starting from version 72.
  • The safari browser supports this feature starting from version 14.1.
Availability: 

Example

Wrongcss
.badge {
  transform: translate(-50%, -50%);
}
.badge:hover {
  transform: rotate(10deg);
}
Rightcss
.badge {
  transform: translate(-50%, -50%);
}
.badge:hover {
  rotate: 10deg;
}

The rotate property adds rotation on top of the existing transform, so the badge stays in place.

Common mistakes

  • Writing rotate: 45 without a unit, so it is ignored.
  • Expecting rotate to apply after transform, when it is applied before it.

Key points

  • Rotation that must combine with an existing transform uses the rotate property instead of a second transform.
  • 3D axis rotation is written as rotate: x 45deg or rotate: 1 1 0 45deg, without commas.

Interview questions

Can I rotate around the X or Y axis with the rotate property?

Yes. Put the axis before the angle, like rotate: y 180deg, or give a vector such as rotate: 1 0 0 45deg.

Can I animate rotate and transform separately?

Yes. They are separate properties, so each can have its own transition or animation.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy