Creating Motion Components
Any HTML or SVG element can be animated by prefixing it withmotion.:
Basic Animation
Animate any animatable property using theanimate prop:
Animation Props
initial
Defines the starting state before animations begin:
false to disable initial animations:
animate
Defines the target animation state:
transition
Configures how the animation runs:
Transition Types
Tween (default)Style Prop
Thestyle prop is enhanced to support MotionValues and transform properties:
Transform Properties
Transform properties can be set individually instead of as a string:x,y,ztranslateX,translateY,translateZscale,scaleX,scaleYrotate,rotateX,rotateY,rotateZskew,skewX,skewY
Gesture Animations
Motion components respond to user interactions:Hover
Tap/Click
Focus
Drag
Variants
Define reusable animation states:Propagating Variants
Variants automatically propagate to children:Animating CSS Variables
SVG Animations
Motion supports SVG-specific properties:pathLength- Length of SVG path (0-1)pathOffset- Offset of SVG pathpathSpacing- Spacing of SVG path
The m Component
For smaller bundle sizes, use the m component which has reduced features:
m when you don’t need:
- Drag gestures
- Layout animations
- Advanced features
MotionProps Type
For TypeScript users, use theMotionProps type:
Performance Tips
- Prefer transform properties -
x,y,scale,rotateare GPU-accelerated - Use
MotionValues - For values that update frequently - Avoid animating expensive properties - Width, height, top, left cause layout
- Use
layoutprop - For animating layout changes efficiently