CSS propertyTransforms
rotate
Rotates an element by a given angle, independently of the transform property.
- Initial value
none- Inherited
- No
- Animatable
- yes, as an angle
- Applies to
- transformable elements
- JavaScript
element.style.rotate = "45deg"
Example
#CSS
.chevron {
transition: rotate 0.2s;
}
details[open] .chevron {
rotate: 180deg;
}Example HTML
<details style="padding: 8px 12px; border: 1px solid #333; border-radius: 10px;">
<summary style="cursor: pointer; list-style: none; display: flex; justify-content: space-between;">How does rotate work? <span class="chevron" style="transition: rotate .2s;">βΎ</span></summary>
<p style="margin: 8px 0 0">Click and the arrow will rotate by 180 degrees.</p>
</details>
<style>details[open] .chevron { rotate: 180deg; }</style>Preview
Definition and usage
#The rotate property rotates an element around the transform-origin point. You give the angle in degrees (deg), turns (turn), or radians (rad). Positive values rotate clockwise.
If you put an axis before the angle, for example rotate: y 60deg, you get a 3D rotation around the chosen axis. The depth effect appears when the parent has perspective set.
The property works independently of transform, so you can animate the rotation alone and set translation and scale separately.
Syntax
#Syntax
rotate: none | <angle> | <axis> <angle>;Values
#Values in practice
#none
No rotation.
.demo { rotate: none; }45deg
Rotates 45 degrees.
.demo { rotate: 45deg; }-0.1turn
Rotates one tenth of a full turn, counterclockwise.
.demo { rotate: -0.1turn; }x 60deg
Rotation around the horizontal axis. Without perspective, the element simply flattens.
.demo { rotate: x 60deg; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Rotate the arrows of expandable sections with
rotaterather than swapping the icon. The transition then looks smooth. - The
turnunit is easy to read in animations:1turnis a full rotation.
Related entries
#- transformMoves, rotates, scales, or skews an element without affecting the page layout.
- transform-originSets the point an element rotates around and scales from.
- translateMoves an element horizontally, vertically, or in depth, independently of the transform property.
- scaleEnlarges or shrinks an element, independently of the transform property.
Spotted a mistake or missing an example? Write to us.