Overview
Layout animations allow elements to automatically animate to their new position when their layout changes. Motion uses performant transforms to achieve this effect.Props
layout
Iftrue, the component will automatically animate to its new position when its layout changes.
true: Animate both position and size"position": Only animate position (size changes instantly)"size": Only animate size (position changes instantly)"preserve-aspect": Animate size and position only if aspect ratio remains the same
How It Works
Layout animations use performant transforms to animate elements. This technique involves animating an element’s scale, which can introduce visual distortions on:- Children elements
boxShadowborderRadius
Correcting Distortions
Children: Addlayout to immediate children
initial
Layout Transition
Customize the layout animation with thetransition prop.
Event Handlers
onLayoutAnimationStart
Callback when a layout animation starts.onLayoutAnimationComplete
Callback when a layout animation completes.Advanced Props
layoutDependency
Force a layout animation when this value changes.layoutScroll
Measure scroll when layout updates.layoutRoot
Mark as a layout root where all children resolve relatively to it.Examples
Expanding card
List reordering
Grid layout change
Accordion
Position-only animation
Notes
- Layout animations use transforms for performance
- Add
layoutto children to prevent scale distortion - Animate or initialize
borderRadiusandboxShadowfor proper corrections - Works with Flexbox, Grid, and absolute positioning
- Combine with AnimatePresence for entering/exiting elements