CSS 2D Transforms
Master CSS 2D transforms to rotate, scale, skew, and translate elements for dynamic, interactive designs.
CSS 2D transforms manipulate elements in two-dimensional space without affecting document flow.
Transform Functions
Translate
Move elements horizontally and vertically.
.translate {
transform: translate(50px, 100px); /* x, y */
}
.translateX {
transform: translateX(50px);
}
.translateY {
transform: translateY(100px);
}Rotate
Rotate elements around a point.
.rotate {
transform: rotate(45deg);
}
.rotate-negative {
transform: rotate(-90deg);
}Scale
Resize elements.
.scale {
transform: scale(1.5); /* 150% size */
}
.scale-xy {
transform: scale(2, 0.5); /* x, y */
}
.scaleX {
transform: scaleX(1.5);
}
.scaleY {
transform: scaleY(0.8);
}Skew
Slant elements.
.skew {
transform: skew(20deg, 10deg); /* x, y */
}
.skewX {
transform: skewX(20deg);
}
.skewY {
transform: skewY(10deg);
}Combining Transforms
.combined {
transform: translate(50px, 50px) rotate(45deg) scale(1.2);
}
.multi {
transform: translateX(100px) rotateZ(45deg) scale(1.5);
}Transform Origin
.element {
transform-origin: center center; /* Default */
}
.top-left {
transform-origin: top left;
}
.custom {
transform-origin: 75% 25%;
}Practical Examples
Hover Effects
.card {
transition: transform 0.3s ease;
}
.card:hover {
transform: translateY(-10px);
}
.zoom-hover {
transition: transform 0.3s ease;
}
.zoom-hover:hover {
transform: scale(1.1);
}Rotating Badge
.badge {
position: absolute;
top: 10px;
right: 10px;
transform: rotate(15deg);
}Loading Spinner
.spinner {
animation: spin 1s linear infinite;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}Flip Card
.flip-card {
perspective: 1000px;
}
.flip-card-inner {
transition: transform 0.6s;
transform-style: preserve-3d;
}
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
}Best Practices
Transform Best Practices
- Use transforms for animations (GPU-accelerated) - Combine with transitions for smooth effects - Set transform-origin appropriately - Use translate instead of position changes - Test performance on lower-end devices - Remember transforms don't affect layout - Use will-change sparingly for heavy animations
Master 2D transforms to create dynamic, performant animations!
How is this guide?
Last modified:
March 7th, 2026
CSS Transitions
Learn how to create smooth animations between CSS property changes using transitions for enhanced user experience.
CSS Animations
Create complex, keyframe-based animations with CSS to bring your web pages to life with smooth, engaging motion effects.
© 2026CoderrShyamAll Rights Reserved.