Both declarations contain the same two transform functions—translate and rotate—but their ORDER is different, and in CSS that matters a lot.
Key rule
• In the single transform property, functions are applied from right-to-left (a bit like mathematical composition).
transform: A B C; → first C, then B, then A.
So let’s step through what each line actually does:
-
transform: translate(-50%, 0%) rotate(45deg);
• Right-most: rotate(45deg) → element is rotated 45° around its transform-origin.
• Then: translate(-50%, 0%) → the object (now already rotated) is moved left by 50 % of its own width in the rotated coordinate space.
-
transform: rotate(45deg) translate(-50%, 0%);
• Right-most: translate(-50%, 0%) → element slides left by 50 % of its width in the original (unrotated) axes.
• Then: rotate(45deg) → the whole result (now offset) is rotated 45° around the transform-origin.
Why they look different
Picture a square whose transform-origin is its center (the default):
Case 1 (translate AFTER rotate):
• Rotate the square 45°.
• Now translate X by −50 %. Because the axes are rotated, “x” is now on a 45° diagonal, so the square ends up shifted down-left on a diagonal line.
Case 2 (translate BEFORE rotate):
• Translate the square straight left by 50 % (no diagonal yet).
• Rotate everything 45°. The final position looks like a “hinged” motion around the origin: the square swings into a different quadrant.
A quick visualization
Original axes After rotate then translate After translate then rotate
y y’ y’
↑ ↑ ↑
│ │ ╱
│ │ ╱
└──→ x └──→ x’ ╲ (square ends up here)
(square here) (square ends up here)
Try it out
<div class="a">A: translate then rotate</div>
<div class="b">B: rotate then translate</div>
<style>
div {width:100px;height:100px;background:#f90;color:#fff;
position:absolute;top:120px;left:120px;transform-origin:center;}
.a {transform:translate(-50%,0%) rotate(45deg);}
.b {transform:rotate(45deg) translate(-50%,0%);}
</style>
Both start at (120 px, 120 px) but end up in noticeably different spots.
How to choose which one to use
• If you want an element to rotate in place and THEN scoot along its new diagonal, do translate(...) rotate(...).
• If you need it to shift first in normal screen axes and THEN spin around its origin, do rotate(...) translate(...).
Tip: when you need more control, set transform-origin explicitly (e.g., transform-origin: top left;)—that’s the point all transforms pivot around.
In short: same functions, different order → different result, because transforms compose right-to-left.