The transform
property in CSS allows you to visually manipulate an element in 2D or 3D space. You can rotate, scale, translate (move), or skew elements without changing the actual document layout.
🔹 What Can transform
Do?
- 📦 Move elements (
translate
) - 🔁 Rotate elements (
rotate
) - 🔍 Resize elements (
scale
) - 🔄 Skew elements (
skew
) - 🌐 Combine transformations (e.g.
rotate
+scale
) - 🧊 Apply 3D effects (with
perspective
androtate3d
)
📘 Syntax
selector {
transform: none | <transform-function> [<transform-function>...];
}
You can combine multiple functions in a single transform
statement.
💡 Transform Functions
Function | What It Does | Example |
---|---|---|
translate(x, y) | Moves the element in 2D space | translate(50px, 20px) |
scale(x, y) | Scales width and height | scale(1.5, 1.5) |
rotate(angle) | Rotates the element | rotate(45deg) |
skew(x, y) | Skews the element along X and/or Y | skew(20deg, 10deg) |
matrix(...) | Combines all above (complex math) | Rarely used manually |
perspective(n) | Sets perspective for 3D transforms | Used with transform-style |
✍️ Example: Rotate an Element
<div class="rotate-box">🎉</div>
.rotate-box {
transform: rotate(30deg);
}
✅ This spins the element 30 degrees clockwise.
✍️ Example: Hover Zoom with scale()
.zoom:hover {
transform: scale(1.2);
}
✅ When hovered, the element enlarges 20%.
✍️ Example: Translate (Move) Element
.mover {
transform: translate(100px, 50px);
}
✅ The element shifts right 100px and down 50px, without affecting layout flow.
🖼️ Image Idea: Visual Representation
Image Panels:
- Original element
- Rotated 45°
- Scaled 1.5x
- Skewed 20°
- Translated (moved)
🎯 Purpose: Show how the same element is changed by each transform function.
🧠 Combine Multiple Transforms
.multiple {
transform: translateX(50px) rotate(15deg) scale(1.1);
}
✅ Combines move + rotate + zoom for dynamic effects.
🧪 Bonus: 3D Transform Example
.cube {
transform: rotateX(45deg) rotateY(30deg);
transform-style: preserve-3d;
}
✅ Adds a 3D twist to your element. Use with perspective
for depth.
⚠️ Important Notes
transform
doesn’t affect surrounding elements (it’s purely visual).- Animations and transitions work beautifully with
transform
. - Combine with
transition
for smooth effects:
.card {
transition: transform 0.3s ease;
}
.card:hover {
transform: scale(1.1) rotate(3deg);
}
✅ Summary
Property | transform |
---|---|
Purpose | Visually manipulate elements in space |
Common Functions | translate , rotate , scale , skew |
Combine? | ✅ Yes (space-separated functions) |
Works with | transition , animation , hover |
🔚 Final Thought
CSS transform
turns ordinary elements into animated, interactive, and visually engaging experiences. From simple button hovers to complex 3D cards — it’s one of the most versatile tools in your CSS toolkit.