Shared layout animations with layoutId
Giving components the same layoutId makes one animate into the other when it replaces it. A common use is an underline that moves between tabs.
How it works
- Render the underline under the active tab. Each tab renders a
motion.divwithlayoutId="underline", but only while it is the active tab. Whenactivechanges, the underline animates from the old tab to the new one. [1] - Namespace it with LayoutGroup. All layoutIds in an app share one global context. Wrapping the tabs in
LayoutGroup id="tabs"scopes theunderlineid to this tab bar. [1]
Run and edit it
It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.
Checked Oct 12, 2026: it starts without errors in Chromium with framer-motion 14.1.0, react 19.3.0, react-dom 19.3.0. Needs WebGL.
More Framer Motion examples
The animate prop in Framer Motion Drag with useTransform in Framer Motion useSpring in Framer Motion Hover and tap gestures in Framer Motion
Sources
Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.