Layout animations
Set layout on a motion.* element to animate size or position changes. Motion measures the
before and after boxes, then animates the difference.
<motion.div layout class={open() ? 'expanded' : 'collapsed'} />
Shared layout
Give two motion elements the same layoutId to animate between them, even across components or
routes. Pair it with <LayoutGroup> or <AnimatePresence> for tabs, expanding cards, and shared
hero transitions.
<motion.span layoutId="active-pill" />
π
Caveats
- Layout animations need measurable ancestors;
position: relative | absolute | fixedis safest. - A direct child of a
layoutelement cannot itself beposition: absolute; usemotion.divwithstyle={{ position: 'absolute' }}andlayoutIdinstead.
See also: LayoutGroup, createInstantLayoutTransition.