Overview
Shared layout animations allow you to animate elements between different components. When a component with alayoutId is removed and another with the same layoutId is added elsewhere, they will visually animate between each other.
Props
layoutId
Enable shared layout transitions between different components with the samelayoutId.
How It Works
When a component with alayoutId is removed from the React tree and another component with the same layoutId is added elsewhere:
- The new component animates from the previous component’s bounding box
- It inherits the previous component’s latest animated values
- If the previous component remains in the tree, they crossfade
Crossfading
layoutCrossfade
Control whether shared layout elements crossfade.false, the element takes its default opacity throughout the animation.
Examples
Animated underline
Image gallery lightbox
Card expansion
Switch toggle
Navigation highlight
List item transfer
Page transitions
Notes
layoutIdmust be unique within the rendered tree at any given time- Works seamlessly with AnimatePresence for exit animations
- Inherits animated values from the previous component
- Crossfades by default when both elements exist simultaneously
- Combine with
layoutprop for full layout animation support - Performance is optimized using transforms