December 4, 2026
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.
What are the four steps?
| Step | What you do |
|---|---|
| First | Measure each element with getBoundingClientRect(). |
| Last | Apply the change (add a class, reorder, filter) and measure again. |
| Invert | Work out the difference and apply it as a transform, so the element appears not to have moved. |
| Play | Animate 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?
- Filtering a grid. Hide some tiles and the rest glide to close the gaps.
- Expanding a card. Add a class that makes one tile fill the stage, and it grows from where it was.
- Reordering a list. Sort or drag items and they slide past each other.
- Switching layouts. Change a grid to a list or a stack with one class.
What should I watch for?
- Scaling distorts content. Text and rounded corners stretch while a scale is in progress. For big size changes, animate position only and fade the content.
- Interruptions. If a new change starts mid-flight, the "First" measurement includes the running transform. That is usually what you want, because the element continues from where it appears to be.
- Reduced motion. Pass a duration of 0 when the visitor asks for less motion.
Which finished examples can I copy?
| Element | What it does |
|---|---|
| Flip filter grid | A tile grid with category filters: the remaining tiles animate to their new places. |
| Grid zoom layout | Clicking a tile zooms it with a FLIP transform to fill the stage. |
| Scroll layout flip | A pinned row of tiles that re-flows into a grid, a feature view or a fanned stack as you scroll. |
| Grid to slider | Click a tile and the whole grid glides into a vertical slider centred on it. |
| Flip bento grid | A 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.