Full answer
Changing top or left changes layout. The browser may need to recalculate the position of this element and sometimes of its neighbours, and then repaint. transform: translate() moves the element after layout is done. Layout is not recomputed, other elements do not move, and the browser can often move the already painted layer on the compositor. That is why it is the usual choice for animations and drag effects.
There are other differences.
translate()does not take the element out of flow. The original space stays reserved.- Percentages in
translate()refer to the element's own size, whiletopandleftpercentages refer to the containing block. That makes centring tricks easy. - A transform can use fractions of a pixel, so slow motion looks smooth. Text can look slightly blurry when it lands between pixels.
- An element with a transform becomes a stacking context and a containing block for fixed-position children.
For .b, offsetLeft stays at 50 (layout position) while its drawn position is 150. Box .c is centred exactly, using its own half width and height. The gold box with translateX(60px) is drawn 60px to the right, but the next gold box stays where it was, because layout did not change.
To animate position smoothly, transition transform. For centring alone, grid is simpler today: display: grid; place-items: center on the parent.
<style>
body { margin: 0; }
.stage { position: relative; width: 400px; height: 120px; background: #eee; }
.a, .b, .c { position: absolute; width: 80px; height: 40px; }
.a { background: tomato; top: 10px; left: 50px; }
.b { background: seagreen; top: 60px; left: 50px; transform: translate(100px, 0); }
.c { background: steelblue; top: 50%; left: 50%; transform: translate(-50%, -50%); }
.flow { display: inline-block; width: 40px; height: 20px; background: gold; }
.flow.moved { transform: translateX(60px); }
</style>
<div class="stage">
<div class="a" id="a"></div>
<div class="b" id="b"></div>
<div class="c" id="c"></div>
</div>
<span class="flow moved" id="m"></span><span class="flow" id="n"></span>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- top and left change layout; translate does not.
- translate keeps the element's original space in the flow.
- Percentages in translate refer to the element's own width and height.
- A transform creates a stacking context and a containing block for fixed descendants.
- Animate transform and opacity for smooth motion; keep top and left for final layout.
Common mistakes
- assuming a transform frees up space. The element's original box stays in layout, so neighbours do not shift to fill the gap.
- adding will-change: transform to many elements. Each one can allocate its own layer and use memory. Add it only to elements that really animate, and remove it after.
Follow-ups
- is the translate property different from transform: translate()?
- Why does translate(-50%, -50%) centre an element of unknown size?
- What does will-change: transform tell the browser, and what does it cost?
Tips
- Use transform for movement and opacity for fading. Keep top and left for the final layout position.
- Mention the layout, paint and composite steps in your answer. It shows the reason, not just the rule.
- Name one downside, such as slightly blurry text at fractional pixel positions.