π CSS rotate: Property (Individual Transform Property) β Complete Tutorial
The rotate: property is part of the **Individual Transform Properties** in CSS, introduced to make transforms easier and more modular. Instead of writing all transforms in one transform: declaration, you can now write:
>>βrotate: 45deg;β instead of βtransform: rotate(45deg);β
Note
β Cleaner, modular transform control
β Animates smoothly
β Combines with scale:, translate:, and transform:
β Part of CSS Transforms Level 2
β Animates smoothly
β Combines with scale:, translate:, and transform:
β Part of CSS Transforms Level 2
π¦ Syntax
rotate syntax
rotate: <angle>;
/* Example */
rotate: 45deg;The angle can be in deg, rad, grad, or turn.
π― Why Use rotate: Instead of transform:?
- β Easier to understand and maintain
- β You can animate/change rotation without affecting other transforms
- β Cleaner code in components
- β Works along with other individual transform properties
π¨ 1. Basic Rotation
Basic rotate:
.box {
rotate: 45deg;
}π¨ 2. Negative Rotation (Counterclockwise)
Negative rotate:
.icon {
rotate: -30deg;
}π¨ 3. Rotate Using Turn Unit
turn unit
.wheel {
rotate: 0.5turn; /* same as 180deg */
}π¨ 4. Hover Rotate Effect
hover rotate
.btn {
transition: rotate .3s ease;
}
.btn:hover {
rotate: 90deg;
}π¨ 5. Rotate From a Different Pivot
Combine with transform-origin to change the rotation anchor point.
rotate with origin
.card {
transform-origin: top left;
rotate: 25deg;
}π¨ 6. Animation Using rotate:
spin animation
.loader {
animation: spin 1s linear infinite;
}
@keyframes spin {
to {
rotate: 360deg;
}
}π¨ 7. Combine rotate: with scale: and translate:
combined transforms
.card {
rotate: 20deg;
scale: 1.1;
translate: 20px 10px;
}Individual transform properties make combined transforms more readable.
π rotate: vs transform: rotate()
| Feature | rotate: | transform: rotate() |
|---|---|---|
| Modular | β Yes | β No (all transforms grouped) |
| Better animations | β | β |
| Affects only rotation | β Does NOT override scale/translate | β Overrides unless combined manually |
| Browser support | Modern browsers | All browsers |
π§ͺ Real-World Examples
1οΈβ£ Accordion Arrow Rotation
arrow rotate
.arrow.open {
rotate: 90deg;
}2οΈβ£ Loading Spinner
spinner
.spinner {
animation: spin 1s linear infinite;
}
@keyframes spin {
to { rotate: 1turn; }
}3οΈβ£ Badge Tilt Effect
tilt badge
.badge {
rotate: -10deg;
}β οΈ Common Mistakes
- β Using rotate: in unsupported older browsers
- β Expecting rotate: to work without transforms enabled
- β Using rotate: and transform: on the same element without knowing precedence
Note
If both transform: and individual transform properties are used,individual properties override the related part of transform.
π₯ Summary
rotate: is the modern, cleaner, modular way to rotate elements in CSS. It simplifies animations, hover effects, and UI transformations while working seamlessly withscale: and translate:.
- rotate: β set rotation directly
- Easier maintenance than transform
- Great for animations (pure CSS)
>>βrotate: is the future of CSS transforms β simple, modular, and readable.β