Two properties can be animated without the browser doing any layout or
painting work: transform and opacity. Everything else
is more expensive, and the difference is not a matter of degree. Animatingleft makes the browser recompute the position of that element and
everything affected by it, on every frame; animatingtransform: translateX() moves an already painted layer.
Which gives one rule that covers most of this subject. To move something, usetransform: translate, not top or left. To
resize it, use transform: scale, not width orheight. To fade it, use opacity. Anything else in an
animation is worth a second look and usually has a version in those three.
Transitions and keyframes are for different things
- A
transitionanimates between two states the element already
has, such as hover or a class being added. It needs no timeline and it
interrupts cleanly when the state changes back @keyframeswithanimationdefines its own
timeline, so it can run without a state change, repeat, and hold several
steps- A transition on
allis the one to avoid: it animates
properties you did not mean, including ones added later, and it is a
performance bug that arrives with an unrelated change transition: transform 200ms ease-outnames the property, the
duration and the curve, and every part of it is a decision
The curve is the part that gets left at the default.ease-out is right for something arriving, because it decelerates
into place; ease-in is right for something leaving. Usingease-in-out for everything is why a lot of interface motion feels
sluggish at exactly the moment the user is waiting.
Three parts of CSS motion
Matching transitions, keyframes and easing curves to the job
Picking the right mechanism and curve avoids sluggish interfaces and accidental performance bugs from transition: all.
- transitionMoves between two existing states like hover or class toggle
- No timeline needed
- Interrupts cleanly on reverse
- Name property like transform 200ms ease-out
- Never animate all
- Timing curvesDecides whether motion feels crisp or sluggish
- ease-out for elements arriving
- ease-in for elements leaving
- Avoid ease-in-out as a lazy default
- @keyframesDefines its own timeline with animation
- Runs without a state change
- Can repeat continuously
- Holds multiple intermediate steps
Leaving easing at ease-in-out is why interface motion often feels slow at the exact moment a user is waiting.
Interactive Practice Lab
Edit and run this snippet directly in your browser (zero setup)
.demo { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px;}.box { flex: 1 1 80px; text-align: center; background: #0ea5e9;}Live Big-O Complexity & Binary Search Race Lab
Compare complexity curves at scale and watch Linear vs Binary Search race live.
The media query that is not optional
@media (prefers-reduced-motion: reduce) is set by people for
whom motion causes nausea or migraine, and honouring it is not a nicety. The
implementation is short: inside that query, setanimation-duration: 0.01ms andtransition-duration: 0.01ms with!important, which ends every animation immediately while still
firing the events that code may be waiting on.
Accessible motion reset
Why 0.01ms beats zero for prefers-reduced-motion
Using a near-zero duration stops visible movement immediately without breaking JavaScript event listeners.
- Reduced motion activeUser sets prefers-reduced-motion: reduce to prevent nausea or migraine
- Set 0.01ms !importantApply to animation-duration and transition-duration instead of 0 or none
- Instant completionEnds visible movement immediately on screen
- transitionend still firesCleanup scripts finish normally instead of leaving elements half open
Removing the animation completely causes transitionend scripts to hang forever, leaving bugs only for users who rely on reduced motion.
Setting the duration to zero rather than removing the animation is the
detail. A script listening for transitionend to clean up will
otherwise wait forever, so the element is left in a half open state, and that
bug only appears for the users who most needed the query to work.
What to run in 2026
The browser's animation panel is the tool, free in every browser. It lists
running animations, lets you slow them down, and shows the curve as a graph,
which is how you find out that a 400ms transition is actually two of them
overlapping. It replaced changing a duration and watching, which cannot separate
two animations that start together.
Six properties, one question
Does animating this avoid a layout pass
A yes here means the browser can move an already painted layer; a no means it recomputes positions on every frame of the animation.
- Yestransformtranslate, scale and rotate. The answer to almost every movementYes
- YesopacityA fade, and the only other one that is freeYes
- Noleft and topRecomputes the position of this element and its neighboursNo
- Nowidth and heightA full layout pass, which is what makes a dropdown stutterNo
- Nobox-shadow and filterNo layout, but a repaint, so cheaper than height and not freeNo
- Not checkedYour page, on your users' devicesNobody measured. Paint flashing answers it in ten secondsNot checked
Use the browser animation panel to spot overlapping 400ms transitions and paint flashing to verify your real page instead of trusting rules alone.
The paint flashing and layer tools in the same panel are the second, also
free. Paint flashing highlights every area being repainted, so an animation that
should be free lights up the whole page when it is not, which is the direct
measurement of the first paragraph. It replaced trusting the property list on
this page, which is a good rule and not evidence about your page.
Where this stalls people
The stall is animating a property that triggers layout and blaming the
device. A dropdown that animates height from 0 is smooth on a
laptop and visibly stutters on a mid range phone, and the conclusion drawn is
that the phone is slow rather than that the animation asks for a full layout pass
sixty times a second.
Fixing dropdown stutter
From layout-thrashing height to grid-template-rows
Animating height from 0 triggers a full layout pass sixty times a second, so the real fix is changing the property rather than shortening duration.
- 04grid-template-rows 0fr to 1frExpands collapsible panels cleanly without squashing inner contentClean CSS fix
- 03max-height with known boundViable when the maximum expanded height is predictableBounded workaround
- 02transform: scaleYAvoids layout but squashes the content inside the boxDistorts text
- 01height from 0Smooth on a laptop, visibly stutters on a mid-range phoneFull layout
Blaming the phone for a stuttering dropdown hides the real problem: asking the browser for a full layout pass every frame.
The fix is usually a different property rather than a shorter duration.
Height is the hard case, because transform: scaleY distorts the
content, and the current answers are animating grid-template-rows
from 0fr to 1fr, or amax-height with a known bound. Both are worth knowing because the
naive version of this is on every site. What the layout underneath is doing is
margin, border, padding, and
where widths go wrong, what any of it costs overall is
why a page feels slow, and what
actually fixes it, and the styles it all lives in are
how a page is laid out and how it looks.