Layout Animation Performance
You'll learn: how Framer Motion optimizes layout animations under the hood and what performance tradeoffs exist when animating layout properties.
The Fundamental Problem
Layout animations are expensive by nature. When you animate properties like width, height, top, left, or trigger layout shifts, the browser must:
- Recalculate layout (reflow)
- Repaint affected pixels
- Composite layers
This happens on every frame—potentially 60 times per second. Unlike transform or opacity (which run on the GPU compositor thread), layout changes block the main thread.
The FLIP Technique
Framer Motion automatically applies the FLIP technique when you use the layout or layoutId props:
- First: Record initial position/size
- Last: Let the DOM update naturally
- Invert: Calculate the difference and apply a reverse transform
- Play: Animate the transform back to 0
This converts expensive layout animations into cheap transform animations. The element appears to animate its layout, but it's actually animating scale and translate under the hood.
// This LOOKS like it animates width/height,
// but Framer Motion transforms it into scale animations
<motion.div layout>
{expanded ? "Long content..." : "Short"}
</motion.div>
When Performance Suffers
- Many layout elements: Animating 50+ elements simultaneously can still overwhelm the system
- Complex child hierarchies: Deep nesting means more measurements
- Rapid state changes: Interrupting FLIP calculations before completion
The layout prop is brilliant for individual elements or small groups. For large lists, consider alternatives like virtualization or staggered animations.
Key Takeaway: Framer Motion's layout prop automatically converts layout animations into performant transform animations using FLIP, but even optimized layout animations have limits at scale.