Skip to main content
Radix Primitives are built with animation in mind. Components expose data attributes that make it easy to target different states, and the Presence component handles exit animations.

Data State Attributes

Most interactive Radix components provide data-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 the Presence 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 the forceMount prop:
When using forceMount, you’re responsible for handling the component’s presence and animations manually.

Animation Libraries

Framer Motion

Use Framer Motion with the asChild 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 transform and opacity for better performance (GPU-accelerated)
  • Avoid animating width, height, or margin when possible
  • Use will-change sparingly and remove it after animations complete
  • Test animations on lower-end devices