2D Transforms: translate, rotate, scale, skew and the Individual Transform Properties
Moving, rotating, scaling and skewing without affecting layout: transform and its 2D functions, percentages relative to the element, the translate, rotate and scale properties and their fixed order, and side effects on stacking and overflow.
kvi5hnuCode Sprout team member7 min readOn this page
A transform changes how an element is drawn: moved, rotated, scaled or slanted, without changing its place in the layout. Neighbors don't move out of the way, and nothing reflows. That makes transforms ideal for animation, hover effects and fine adjustments.

The transform property
transform takes a space-separated list of functions:
.card:hover { transform: translateY(-4px) scale(1.02); }
.badge { transform: rotate(-8deg); }
.mirror { transform: scaleX(-1); }
| Function | Values | Effect |
|---|---|---|
translate(x, y), translateX(), translateY() | lengths or percentages | moves the element; translate(x) means y = 0 |
rotate(a) | an angle: deg, turn, rad, grad | rotates clockwise for positive angles |
scale(x, y), scaleX(), scaleY() | numbers or percentages | resizes; one value scales both axes; negative values mirror |
skew(x, y), skewX(), skewY() | angles | slants the element along an axis |
matrix(a, b, c, d, e, f) | six numbers | any 2D transform at once (article 104) |
Some details:
- Percentages in translations are relative to the element's own size (its border box), not its container.
translate(-50%, -50%)moves an element back by half its own width and height, which is why it's used for centering. Tested in Chrome:translate: 50% 50%moved a 100 × 50px box by 50px and 25px. scale()takes numbers:scale(1.5), orscale(150%). Lengths are invalid.- Angles need a unit. One invalid function makes the whole value invalid: tested in Chrome,
transform: rotate(45) scale(2)computed tonone. skew(x, y)isn't the same asskewX(x) skewY(y), and the spec discouragesskew()with two values; useskewX()andskewY(). There's noskewproperty.getComputedStyle()returns anytransformother thannoneas amatrix()(ormatrix3d()for 3D). Tested in Chrome:rotate(45deg) scale(2)read back asmatrix(1.41421, 1.41421, -1.41421, 1.41421, 0, 0). That's whygetComputedStyle()rarely shows your original functions.
A later rule replaces the whole list
transform is one property, so each declaration replaces the previous list rather than adding to it:
.icon { transform: rotate(45deg); }
.icon:hover { transform: scale(1.2); } /* the rotation is lost on hover */
.icon:hover { transform: rotate(45deg) scale(1.2); } /* restate it */
The individual properties below avoid this problem.
Order matters
Functions apply from left to right, each in the coordinate system left by the previous ones. Rotating first turns the element's axes, so a following translation moves along the rotated axis. Tested in Chrome, with a 100 × 50px box and transform-origin: 0 0:
translate(100px, 0) rotate(90deg)placed the box at 50px from the left, at the top.rotate(90deg) translate(100px, 0)moved it 100px down, since the x-axis now pointed downward.scale(0.5) translateX(100px)moved the box only 50px, because the translation happened at half scale, whiletranslateX(100px) scale(0.5)moved it 100px.

Follow the small arrow: after rotate(90deg) it points down, and that's the direction the following translate() moves the box.
Individual transform properties
translate, rotate and scale are separate properties, so each can be changed, transitioned or animated independently:
.card {
translate: 0 0;
scale: 1;
transition: translate 0.2s, scale 0.3s;
}
.card:hover { translate: 0 -4px; scale: 1.02; } /* no need to restate anything */
.card.flagged { rotate: -2deg; } /* combines with the hover */
| Property | Values |
|---|---|
translate | x, x y or x y z: lengths or percentages |
rotate | an angle (2D), or an axis and angle: x 45deg, y 45deg, 1 1 0 45deg |
scale | one number for both axes, or x y, or x y z |
They apply in a fixed order: translate, then rotate, then scale, then transform, whatever order you write them in. Tested in Chrome:
translate: 100px 0; rotate: 90deggave exactly the same box astransform: translate(100px, 0) rotate(90deg).- With
translate: 10px; scale: 2; transform: translateX(5px)andtransform-origin: 0 0, the box's left edge was at 20px: thetransformtranslation was applied last, inside the scale, so it counted double.
When you need a different order, use transform for that part.
What transforms affect
Transforms don't change layout, but any value other than none:
- creates a stacking context (article 58);
- becomes the containing block for
position: fixedandabsolutedescendants. Tested in Chrome: aposition: fixed; top: 0; left: 0child of an element withtransform: translate(0)was placed at its parent's corner, not the viewport's; - adds to the scrollable overflow of its container. Tested in Chrome: a 100px box moved with
translateX(2000px)made the page 2100px wide, with a horizontal scrollbar. Useoverflow: clipon a wrapper when an animation slides things in from outside.
Transforms don't apply to non-replaced inline boxes, like a <span> or <a> in a line of text. Tested in Chrome: a display: inline span with transform: translateX(50px) didn't move. Give it display: inline-block. They do apply to images and other replaced elements, and to blocks, flex and grid items, and table cells.
Transforms are drawn on the GPU in most browsers and don't trigger layout, so animating transform, translate, rotate, scale and opacity is the most efficient kind of animation (article 111).

All three are the bullet points above, rendered: layout ignores the transform, inline boxes ignore it entirely, and a transformed parent captures fixed children.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0.2rem 0.6rem; }
label { display: flex; align-items: center; justify-content: space-between; gap: 0.3rem; } label input { inline-size: 5rem; }
.stage, .slot { position: relative; block-size: 7.5rem; display: grid; place-items: center; }
.ghost, .box { grid-area: 1 / 1; inline-size: 4.5rem; block-size: 2.8rem; border-radius: 6px; }
.ghost { border: 2px dashed #b9a993; }
.box { display: grid; place-items: center; font-weight: 800; color: white; background: #8a3b12; }
#box { /* individual properties: always translate → rotate → scale → transform */
translate: var(--tx, 0px) 0;
rotate: var(--rot, 0deg);
scale: var(--sc, 1);
transform: skewX(var(--sk, 0deg));
}
.order { display: grid; grid-template-columns: 1fr 1fr; overflow: clip; }
.slot { justify-items: start; padding-inline-start: 0.5rem; }
.a { transform: translate(40px) rotate(45deg); background: #1d3557; }
.b { transform: rotate(45deg) translate(40px); background: #2f7d32; }
.note { margin: 0.3rem 0 0; color: #555; }
The dashed outlines show the layout boxes, which never move. In the bottom row, the same two functions in different orders put the box in different places: B was rotated first, so it moved 40px along its tilted x-axis.
What's current
transformand the individualtranslate,rotateandscaleproperties: all browsers.- Prefer the individual properties for independent changes and animations.
Common questions
Why did my element lose its rotation on hover?
The hover rule's transform replaced the whole list. Restate it, or use the individual rotate and scale properties.
Why doesn't my transform work on a link?
Inline elements aren't transformable. Use display: inline-block.
Why does my animation add a horizontal scrollbar?
Transformed elements add to scrollable overflow. Clip it with overflow: clip on a wrapper.
What does translate(-50%, -50%) refer to?
The element's own width and height, not the parent's.
Summary
- Transforms change drawing, not layout; neighbors don't move.
transformtakes functions applied left to right; a later declaration replaces the whole list.- Translation percentages are relative to the element itself; an invalid function invalidates the whole value.
translate,rotateandscaleare independent properties, applied in that fixed order beforetransform.- Transforms create a stacking context and a containing block, add scrollable overflow, and don't apply to inline boxes.
Practice questions
Write a hover effect that lifts a card 6px and enlarges it 3%, without affecting a separately set rotation.
Answer
.card { transition: translate 0.2s, scale 0.2s; }
.card:hover { translate: 0 -6px; scale: 1.03; }
The rotate property, set elsewhere, is untouched.
Where does this box end up, relative to its layout position?
.box { transform: scale(2) translateX(50px); }
Answer
100px to the right (and twice the size, scaled around its center). The translation happens in the scaled coordinate system, so 50px becomes 100px. With translateX(50px) scale(2) it would move 50px.
Why does this element not move?
<a href="#top" style="transform: translateY(-2px)">Back to top</a>
Answer
An <a> is inline by default, and non-replaced inline boxes can't be transformed. Add display: inline-block.
What does transform: rotate(45) translate(10px) do?
Answer
Nothing: rotate(45) has no angle unit, so the whole transform declaration is invalid.
Previous: Styling Forms: appearance, accent-color, field-sizing and Customizable select
Next: Transform Origin, Order of Transforms and the Matrix Functions

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.