transform
Moves, rotates, scales, or skews an element without affecting the page layout.
- Initial value
none- Inherited
- No
- Animatable
- yes, as a transform
- Applies to
- transformable elements (not non-replaced inline elements)
- JavaScript
element.style.transform = "rotate(10deg)"
Example
#.card {
transition: transform 0.2s;
}
.card:hover {
transform: translateY(-4px) scale(1.02);
}<div style="display: flex; gap: 12px; padding: 12px;">
<div class="box" style="transition: transform .2s;" onmouseenter="this.style.transform='translateY(-4px) scale(1.02)'" onmouseleave="this.style.transform=''">Hover over me</div>
<div class="box" style="transition: transform .2s;" onmouseenter="this.style.transform='translateY(-4px) scale(1.02)'" onmouseleave="this.style.transform=''">And me too</div>
</div>Definition and usage
#The transform property changes an element’s appearance using functions: translate() moves, rotate() rotates, scale() scales, and skew() skews. Functions can be combined, and they are applied from right to left relative to the transform-origin point.
A transform does not affect layout: the element visually moves or grows, but its original space stays reserved and its neighbours don’t shift. That makes transforms great for animation.
Browsers animate transform very efficiently, usually on the GPU. Moving an element with transform: translate() is smoother than changing left or margin.
Syntax
#transform: none | <transform-function>+;Values
#- No transform.
- Moves 40px to the right and 20px up.
- Rotates 25 degrees clockwise.
- Enlarges by 30%.
- Skews horizontally.
multiple functions
Rotation and enlargement at the same time.
Values in practice
#none
.demo { transform: none; }translate(40px, -20px)
.demo { transform: translate(40px, -20px); }rotate(25deg)
.demo { transform: rotate(25deg); }scale(1.3)
.demo { transform: scale(1.3); }skew(-15deg)
.demo { transform: skew(-15deg); }rotate(15deg) scale(1.2)
.demo { transform: rotate(15deg) scale(1.2); }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Use
transforminstead oftop,left, ormarginto animate movement. The browser then doesn’t have to recalculate layout. - The order of functions matters:
rotate(45deg) translateX(50px)gives a different result thantranslateX(50px) rotate(45deg).
Related entries
#- transform-originSets the point an element rotates around and scales from.
- translateMoves an element horizontally, vertically, or in depth, independently of the transform property.
- rotateRotates an element by a given angle, independently of the transform property.
- scaleEnlarges or shrinks an element, independently of the transform property.
- transitionA shorthand that makes CSS value changes happen smoothly instead of abruptly.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.