Full answer
A transform changes how a box is drawn (move, rotate, scale, skew) without changing the layout. Other elements do not move, because the original space is still reserved. A transition tells the browser to animate a property over time when its value changes, instead of jumping.
A transition needs four things: which property, how long, how it speeds up (timing function) and an optional delay. They are written transition: transform 0.2s ease-out 0s. The change usually comes from a state such as :hover, :focus-visible or a class added by JavaScript.
Hover over the button and it grows by 10 percent over 0.2 seconds. Move the mouse away and it shrinks back over the same time, because the transition is declared on the base state.
Transform functions are applied right to left in the order written, so translateX(100px) rotate(45deg) is not the same as rotate(45deg) translateX(100px). The transform-origin property sets the pivot point, and it defaults to the centre of the box.
Transitions cannot animate from or to display: none in the normal way, and auto heights do not animate. Animating transform and opacity is usually cheapest because browsers can often handle them without recomputing layout.
<style>
button {
padding: 0.6rem 1.2rem; border: 0; background: #0a6cff; color: #fff; border-radius: 6px;
transform: scale(1);
transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
}
button:hover, button:focus-visible { transform: scale(1.1); box-shadow: 0 4px 10px rgba(0,0,0,.3); }
</style>
<button id="b">Buy now</button>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
- Transform changes how a box is drawn, not the layout.
- A transition needs the property, duration, timing function and optional delay.
- Put the transition on the base state so it also runs on the way back.
- Transform order matters because functions apply right to left.
- Avoid transition: all and animate transform and opacity where you can.
Common mistakes
- transition: all. It animates things you did not intend, such as layout properties, and it makes later changes harder to reason about. List the properties.
- forgetting that transform on an element makes it a containing block for fixed-position children and creates a stacking context.
Follow-ups
- transition or keyframes animation?
- Why does a transform create a stacking context?
- How do you animate an element in from display: none?
Tips
- Put the transition on the base rule, not only on :hover, if you want the return animation too.
- Describe the hover button example: base state, hover state, transition on base.
- Mention reduced motion preferences when you talk about animation.