rotate
Example
.badge {
transform: translate(-50%, -50%);
}
.badge:hover {
transform: rotate(10deg);
}.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: 45without a unit, so it is ignored. - Expecting
rotateto apply aftertransform, when it is applied before it.
Key points
- Rotation that must combine with an existing
transformuses therotateproperty instead of a secondtransform. - 3D axis rotation is written as
rotate: x 45degorrotate: 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.