FLIP animation: smooth layout changes with transforms and springs

When an item is added, removed or wraps to a new row, the browser moves everything around it at once, in a jump. Animating top, left, width or height to smooth that out forces layout on every frame. FLIP measures where things were and where they end up, then animates only transform, which the browser can do without laying the page out again.

Live example: Chip Tags, https://motionmart.store/p/latch/chip-tags. Glossary entry: https://motionmart.store/glossary/flip-animation

1. First: measure before the change

Record getBoundingClientRect() for every element that might move: the items in the list, and anything after them, such as the text field at the end of a tag row.

2. Last: make the change and measure again

Change the DOM: add the chip, remove it, reorder the list. Then read the new rectangles. The browser lays the page out once, here, and never again during the animation.

3. Invert: put everything back where it was

For each element, set a transform that moves it by the old position minus the new one. It now appears exactly where it was before the change, although the layout already says otherwise.

4. Play: animate the transform to zero

Animate that transform back to none. Each element glides from its old place to its new one, and only transform changes, so it stays smooth.

function flip(elements, change) {
  const first = new Map(elements.map((el) => [el, el.getBoundingClientRect()]));
  change();
  for (const el of elements) {
    const a = first.get(el), b = el.getBoundingClientRect();
    if (!a) continue;
    el.animate(
      [{ transform: `translate(${a.left - b.left}px, ${a.top - b.top}px)` }, { transform: 'none' }],
      { duration: 300, easing: 'cubic-bezier(.2, .8, .2, 1)' },
    );
  }
}

Run it on a spring

A fixed duration looks wrong when a second change arrives mid-move: the element restarts from somewhere else. Keep a position and velocity per element instead and step a spring toward zero every frame. A new change measures the element where it is on screen, because getBoundingClientRect includes the current transform, so the move carries on from there without a jump.

Chip Tags springs each chip back with a stiffness of 260 and a damping of 17, so a new chip nudges its neighbours and they settle with a small overshoot. The same spring math, turned into CSS, is in the spring guide.

The scaled-parent trap

getBoundingClientRect returns screen pixels, after any CSS scale on an ancestor, but a translate inside the element is in its own, unscaled pixels. In a scaled preview or a zoomed card the chips would overshoot or fall short. Divide the measured difference by the scale, which you can read as rect.width / element.offsetWidth of the scaled container. Chip Tags does this on every move.

When not to use FLIP

Questions

What does FLIP stand for?

First, Last, Invert, Play: measure before the change, measure after it, transform elements back to where they were, then animate the transform away.

Does FLIP work in React and Vue?

Yes. Measure before the update and play after it, for example in useLayoutEffect in React or with nextTick in Vue. Motion’s layout prop runs a similar transform-based animation for you.

Why animate transform instead of top and left?

Changing top, left, width or height makes the browser lay the page out again on every frame. Transform is applied after layout, so the animation stays smooth.

Browse by use case