Rotate, scale, move, and skew elements in two dimensions
2D transforms let you manipulate elements in two-dimensional space. You can rotate, scale, move, and skew elements without affecting the document flow. Perfect for animations, hover effects, and creative layouts.
Key Advantage: Transforms are hardware-accelerated and don't trigger layout recalculations, making them very performant.
Rotates an element around a fixed point.
transform: rotate(45deg);
Values: Degrees (deg), turns (turn), radians (rad)
Example: rotate(90deg) rotates 90 degrees clockwise
Negative values: Rotate counterclockwise
Increases or decreases element size.
transform: scale(1.5);transform: scale(2, 0.5);
One value: Scales both width and height equally
Two values: scale(x, y) - horizontal and vertical separately
Example: scale(2) doubles the size, scale(0.5) halves it
Moves an element from its current position.
transform: translate(50px, 100px);
Values: translate(x, y)
Example: translate(50px, 100px) moves 50px right, 100px down
Individual axes: translateX(50px) or translateY(100px)
Centering trick: translate(-50%, -50%) with position: absolute
Tilts an element along the X or Y axis.
transform: skew(20deg, 10deg);
Values: skew(x-angle, y-angle)
Example: skew(20deg) tilts horizontally
Individual axes: skewX(20deg) or skewY(10deg)
Sets the point around which transformations occur.
transform-origin: center center;transform-origin: top left;
Default: center center (50% 50%)
Values: Keywords (top, bottom, left, right, center) or percentages/pixels
Example: Rotate from top-left corner instead of center
Combine multiple transform functions in one declaration.
transform: rotate(45deg) scale(1.5) translate(50px, 0);
Order matters: Functions apply from right to left
Example: Element is first translated, then scaled, then rotated