Layout animation
Also called FLIP animation or auto layout animation
An animation that smoothly moves and resizes elements when the layout changes, such as list items gliding to new spots after a sort or filter.
import { useState } from 'react';
import { AnimatePresence, motion, MotionConfig } from 'motion/react';
const tasks = [
{ id: 1, title: 'Write launch email', done: false },
{ id: 2, title: 'Review pricing page', done: true },
{ id: 3, title: 'Fix signup redirect', done: false },
{ id: 4, title: 'Book venue for offsite', done: true },
{ id: 5, title: 'Draft Q3 roadmap', done: false }
];
const byTitle = [...tasks].sort((a, b) => a.title.localeCompare(b.title));
export function TaskList() {
const [sorted, setSorted] = useState(false);
const [hideDone, setHideDone] = useState(false);
const ordered = sorted ? byTitle : tasks;
const visible = hideDone ? ordered.filter((task) => !task.done) : ordered;
return (
// reducedMotion='user' turns the movement off for people who prefer less motion.
<MotionConfig reducedMotion='user'>
<div className='w-80'>
<div className='mb-3 flex gap-2 text-sm font-medium *:rounded-full *:border *:px-3 *:py-1.5 *:aria-pressed:bg-muted'>
<button
type='button'
aria-pressed={sorted}
onClick={() => setSorted(!sorted)}
>
Sort A–Z
</button>
<button
type='button'
aria-pressed={hideDone}
onClick={() => setHideDone(!hideDone)}
>
Hide done
</button>
</div>
{/* popLayout pulls leaving rows out of the flow, so the rest close the gap right away. */}
<ul className='relative flex flex-col gap-2'>
<AnimatePresence mode='popLayout' initial={false}>
{visible.map((task) => (
<motion.li
key={task.id}
layout
exit={{ opacity: 0, scale: 0.95 }}
transition={{ duration: 0.3, ease: [0.23, 1, 0.32, 1] }}
className='rounded-xl border bg-background px-4 py-3 text-sm'
>
{task.title}
</motion.li>
))}
</AnimatePresence>
</ul>
</div>
</MotionConfig>
);
}Animate the task list when it is sorted or filtered: each row should glide from its old position to its new one over 300ms with ease-out instead of jumping, and removed rows should fade out and scale to 95% while the rest close the gap. Use Motion’s layout prop with AnimatePresence, and make changes instant when prefers-reduced-motion is set.
Paste into Layerwise or any AI coding tool.
What is Layout animation?
When items are added, removed, sorted, or resized, the browser normally jumps everything to its new position in a single frame. A layout animation measures where each element was before the change and where it ends up after, then animates the difference so items glide into place.
Use it for lists that reorder or filter, grids that change columns, cards that expand, tabs with a sliding indicator, and anywhere an instant jump would make people lose track of an item. It is also the engine behind most morphs and shared element transitions.
The classic technique is called FLIP: First, Last, Invert, Play. Measure the first position, apply the change, measure the last position, invert the difference with a transform, then animate that transform back to zero. Because only transform animates, it stays smooth even though the real layout changed instantly. Motion does all of this when you add the layout prop, and AnimatePresence handles items that leave.
Often confused with
- Morph
- A morph is one element changing shape. Layout animation is the general technique that animates any element whose position or size changed, and morphs are often built with it.
Related terms
All termsShared element transition
A transition where an element from one view, like a thumbnail, travels and grows into its place in the next view, linking the two screens.
Drag to reorder
A list you can rearrange by dragging an item to a new spot while the other items slide aside to make room.
Height auto animation
An animation that opens or closes a panel to the exact height of its content, even though that height is unknown ahead of time.
GPU acceleration
A browser technique where the graphics chip moves, fades, or scales an element on its own layer instead of redrawing the page every frame.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.