LayoutGroup component enables coordinated layout animations between multiple motion components. It’s particularly useful for shared layout animations where components animate between different positions in the tree.
Usage
Props
React children. Any
motion components with layout or layoutId props will be coordinated.A unique ID for this layout group. Useful when nesting layout groups.
Controls whether this layout group inherits from parent layout groups:
true: Inherit both the group and ID (default)false: Create an isolated layout group"id": Only inherit the ID, not the group
Shared Layout Animations
UselayoutId to create smooth animations between components:
Examples
Tab Selector
Expanding Cards
Nested Layout Groups
Grid Reordering
TypeScript
How It Works
When components with the samelayoutId are rendered in different positions:
- The old component measures its bounding box
- The new component measures its bounding box
- Motion calculates the difference and animates the transform
- The old component is removed from the tree
LayoutGroup ensures these measurements and animations are coordinated across the entire group.
Notes
- Components with the same
layoutIdmust be within the sameLayoutGroup - Only one component with a given
layoutIdshould be rendered at a time - Layout animations work with both position and size changes
- Use
layoutprop withoutlayoutIdfor independent layout animations
Related
- motion - Core animation component with layout prop
- layout animations guide - Learn more about layout animations
- AnimatePresence - Combine with exit animations