Lesson 21 of 50
cssTransforms
10 mins
Course progress42%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 21 of 50
css10 mins
Keep these ideas in mind as you work through the lesson.
Transforms modify an element's visual rendering without changing its layout footprint. They are extremely cheap for the GPU and form the backbone of most UI motion.
| Function | Description |
|---|---|
translate(x, y) | Moves the element along the X/Y axis. |
rotate(angle) | Rotates around the element’s origin. |
scale(x, y) | Scales width/height proportionally (scale(1.2) equals scale(1.2, 1.2)). |
skew(x-angle, y-angle) | Tilts the element along each axis. |
perspective(<length>) – defines the distance between the viewer and the z‑plane.rotateX(), rotateY(), rotateZ() – rotate around a single axis.translateZ() – move on the z‑axis (creates depth)..card {
perspective:1000px; /* create 3‑D space */
}
.inner {
transition:transform .6s;
transform-style:preserve-3d; /* keep children in 3‑D */
}
.card:hover .inner { /* flip on hover */
transform:rotateY(180deg);
}
.front, .back {
position:absolute; inset:0; backface-visibility:hidden; /* hide backside */
}
.back { transform:rotateY(180deg); }
The card appears to rotate in 3‑D space, revealing its back face.
transform (even transform:none) creates a new stacking context. This means its children will be stacked inside it, unaffected by siblings’ z-index.transform-originChanging the pivot point can make a subtle difference:
button { transform-origin: left center; }
The button now rotates around its left edge instead of the centre.