The layout Prop
Add the layout prop to automatically animate layout changes:
How It Works
Whenlayout is set, Motion:
- Measures the element before and after the layout change
- Calculates the difference
- Applies a transform to animate smoothly between states
- Corrects any visual distortions (like border-radius)
- CSS changes
- Parent layout changes
- Content changes
- Window resizing
Layout Animations with Rotation
Motion correctly handles rotation during layout animations:Shared Layout Animations (layoutId)
Create seamless transitions between different components usinglayoutId:
Complex Shared Transitions
LayoutId works even when elements change position dramatically:LayoutGroup
Wrap multiplelayoutId elements in a LayoutGroup to scope shared layouts:
LayoutGroup Props
Layout with AnimatePresence
Combinelayout with AnimatePresence for smooth list animations:
Scale Correction
Motion automatically corrects visual properties during scale-based layout animations: Corrected properties:borderRadiusboxShadowtransformOrigin
Layout Transitions
Customize layout animation timing:Layout-specific Props
layout="position"
Only animate position changes:
layout="size"
Only animate size changes:
onLayoutMeasure
Callback when layout is measured:
Performance
Layout animations are performant because:- GPU-accelerated - Uses transforms under the hood
- Batched measurements - Reads and writes are batched to prevent layout thrashing
- Projection - Uses a projection technique to avoid recalculating layout
Best Practices
- Use
layoutsparingly - Only on elements that need it - Avoid during scroll - Can cause performance issues
- Group related animations - Use
LayoutGroupto scope - Test on low-end devices - Layout animations can be more intensive