Transform Functions: translate(), rotate(), scale()
You'll learn how to move, spin, and resize elements using CSS transform functions without affecting document flow.
What Are Transform Functions?
Transform functions let you visually manipulate elements in 2D or 3D space. Unlike changing width or position, transforms don't affect layout—they happen in a separate compositing layer, making them smooth and performant for animations.
Think of it like moving a photo on your desk: you can slide it around (translate), spin it (rotate), or make it bigger/smaller (scale) without affecting where other items sit.
The Core Transform Functions
translate()
Moves an element from its original position:
.box {
transform: translate(50px, 20px); /* x, y */
}
.box-x-only {
transform: translateX(100px);
}
rotate()
Spins an element around its center point:
.arrow {
transform: rotate(45deg);
}
.counter-clockwise {
transform: rotate(-90deg);
}
scale()
Resizes an element (1 = original size):
.grow {
transform: scale(1.5); /* 150% size */
}
.shrink {
transform: scale(0.8, 1.2); /* width 80%, height 120% */
}
Combining Multiple Transforms
Chain functions together in one transform declaration:
.card {
transform: translate(20px, 10px) rotate(15deg) scale(1.1);
}
Order matters! The transformations apply from right to left (or in reading order, depending on perspective).
3D Variants
For depth effects, use translateZ(), rotateX(), rotateY(), or scale3d() (requires parent with perspective).
Key Takeaway: Transform functions move, rotate, and resize elements efficiently without disrupting page layout—perfect for interactive effects and animations.