Data State Attributes
Most interactive Radix components providedata-state attributes that reflect their current state. You can use these to apply animations:
CSS Transitions
Use CSS transitions with data attributes for simple animations:Components expose
data-state with values like "open", "closed", "checked", "unchecked", etc.CSS Keyframe Animations
Use CSS keyframes for more complex animations:Example with Accordion
Radix provides CSS variables like
--radix-accordion-content-height and --radix-collapsible-content-width for animating dynamic dimensions.Exit Animations
Radix uses thePresence component internally to handle exit animations. The component stays mounted while animating out, allowing CSS animations to complete.
Force Mount for Animation Control
For advanced animation control, use theforceMount prop:
Animation Libraries
Framer Motion
Use Framer Motion with theasChild prop for advanced animations:
1
Install Framer Motion
2
Use controlled state
Control the
open state to work with AnimatePresence:3
Add forceMount
Use
forceMount to keep the component mounted during animations:4
Wrap with motion components
Use
motion.div with asChild to apply Framer Motion animations:React Spring
Common Animation Patterns
Slide and Fade
Scale and Fade
Rotate Icon
Performance Tips
- Use
transformandopacityfor better performance (GPU-accelerated) - Avoid animating
width,height, ormarginwhen possible - Use
will-changesparingly and remove it after animations complete - Test animations on lower-end devices