Copied!
Guide

The FLIP animation technique, explained with code

When a grid is filtered or a card grows to fill the screen, the items jump to their new places. FLIP makes them glide instead. It stands for First, Last, Invert, Play, and it is about ten lines.

← Blog
Title card: FLIP animation. Preview of the FLIP filter grid element from the Enrichr Library.

December 4, 2026

3 min readFirst, Last, Invert, Play

FLIP is a way to animate a layout change smoothly. You record where each element is, make the change at once, measure where the elements ended up, and then use a transform to slide each one from its old place to its new one. The name stands for First, Last, Invert, Play. It is how filtered grids, reordered lists and expanding cards glide instead of jumping.

Try it on any site. The free animation library checker shows you which animation libraries actually run on a page (GSAP, Lenis, Framer Motion). Paste a URL, no sign-up for your first lookup.

What are the four steps?

StepWhat you do
FirstMeasure each element with getBoundingClientRect().
LastApply the change (add a class, reorder, filter) and measure again.
InvertWork out the difference and apply it as a transform, so the element appears not to have moved.
PlayAnimate the transform back to none.

What is the code?

function flip(elements, change, options = {}) {
  const first = new Map(elements.map((el) => [el, el.getBoundingClientRect()]));

  change();                                            // the real layout change

  for (const el of elements) {
    const a = first.get(el);
    const b = el.getBoundingClientRect();              // Last
    if (!b.width || !a.width) continue;                // hidden before or after
    const dx = a.left - b.left, dy = a.top - b.top;
    const sx = a.width / b.width, sy = a.height / b.height;
    if (!dx && !dy && sx === 1 && sy === 1) continue;

    el.animate([
      { transformOrigin: "0 0",
        transform: `translate(${dx}px, ${dy}px) scale(${sx}, ${sy})` },   // Invert
      { transformOrigin: "0 0", transform: "none" }                        // Play
    ], { duration: 500, easing: "cubic-bezier(0.2, 0.8, 0.2, 1)", ...options });
  }
}
// Example: shuffle a grid and let the tiles glide to their new places
const grid = document.querySelector(".grid");
const tiles = [...grid.children];

document.querySelector(".shuffle").addEventListener("click", () => {
  flip(tiles, () => {
    tiles.sort(() => Math.random() - 0.5).forEach((t) => grid.append(t));
  });
});

Why does this work?

All the measuring and the layout change happen inside one frame, before the browser paints. The visitor never sees the jump. What they see is the first painted frame, where every element is transformed back to its old place, followed by the animation to its real one. The costly layout work happens once, and the animation itself is only transforms.

Where is FLIP useful?

What should I watch for?

Which finished examples can I copy?

ElementWhat it does
Flip filter gridA tile grid with category filters: the remaining tiles animate to their new places.
Grid zoom layoutClicking a tile zooms it with a FLIP transform to fill the stage.
Scroll layout flipA pinned row of tiles that re-flows into a grid, a feature view or a fanned stack as you scroll.
Grid to sliderClick a tile and the whole grid glides into a vertical slider centred on it.
Flip bento gridA 3 by 3 bento grid where the photo under the pointer grows into the big tile.

All are free in the Enrichr Library, with a live demo and copyable code.

Where to go next

FAQ

What does FLIP stand for?

First, Last, Invert, Play. Measure the First position, make the change and measure the Last position, Invert the difference with a transform so the element looks unmoved, then Play the transform back to nothing.

Why not animate width, height, top and left directly?

Those properties make the browser lay the page out again on every frame, which is slow and janky. A transform is handled by the graphics card and does not touch layout.

Do I need the GSAP Flip plugin?

No. The basic technique is short in plain JavaScript. The plugin helps with harder cases such as nested transforms, elements moving between parents and interrupted animations.

What about the View Transitions API?

document.startViewTransition() does a similar job for you: it snapshots the page before and after a change and animates between them. It is the simpler choice where its browser support is enough for you.