AutoAnimate logo

AutoAnimate

Zero-config, drop-in animation utility that adds smooth transitions with a single line of code.

npm install @formkit/auto-animate
13.6K355.9K/weekv0.9.055.1 KBMIT33 issues
Last updated: 2025-09-05
Star history chart for formkit/auto-animate

TL;DR

A zero-config animation utility that automatically adds smooth transitions to your web app whenever the DOM changes.

It is framework-agnostic but includes a dedicated React hook, offering a lightweight alternative to complex motion libraries.

Why AutoAnimate?

Animations often require complex state management, measuring DOM elements, or writing verbose CSS transitions. AutoAnimate flips this paradigm by assuming you want smooth transitions by default. It observes DOM mutations—like adding a list item or hiding a card—and automatically applies the FLIP (First, Last, Invert, Play) technique to animate the changes.

  • Zero Configuration: No keyframes, spring physics tuning, or variants to define. It just works.
  • Single Hook Implementation: The API is effectively one line of code: const [parent] = useAutoAnimate().
  • Performance First: Built on the FLIP technique, ensuring animations are smooth and hardware accelerated where possible.
  • Framework Agnostic Core: While it has a first-class React hook, the core logic works anywhere, making your knowledge portable.
  • Tiny Footprint: Weighs in at roughly 2.5kb, a fraction of the size of heavyweights like Framer Motion or React Spring.

Code Snippet

The beauty of AutoAnimate lies in its simplicity. You attach a ref to a parent element, and any changes to its direct children (additions, removals, or reordering) are automatically animated.

import { useState } from 'react';
import { useAutoAnimate } from '@formkit/auto-animate/react';

const TodoList = () => {
  const [items, setItems] = useState(['Buy milk', 'Walk dog']);
  // 1. Call the hook
  const [parent] = useAutoAnimate();

  const add = () => setItems([...items, `New Task ${Date.now()}`]);

  return (
    <div>
      <button onClick={add}>Add Task</button>
      {/* 2. Attach the ref to the container */}
      <ul ref={parent}>
        {items.map((item) => (
          <li key={item}>{item}</li>
        ))}
      </ul>
    </div>
  );
};

In this example, simply updating the items state triggers a smooth entrance animation for new list items and adjusts the position of existing items automatically.

Pros and Cons

No library is perfect; understanding the trade-offs is key to selecting the right tool.

Pros

  • Unbeatable DX: There is effectively no learning curve. If you know how to use a ref, you know how to use this library.
  • Lightweight: Perfect for projects that need polish without bloating the bundle size.
  • Automatic Layout Handling: Handles complex layout shifts (like a grid reflowing when an item is removed) without manual calculations.

Cons

  • Limited Control: You cannot easily orchestrate complex sequences or stagger animations.
  • Direct Children Only: It only animates the immediate children of the ref-holder. Nested changes require their own refs.
  • Physics Limitations: Unlike spring-based libraries, you don't get realistic physics (bounce, friction) customization out of the box.

Comparison with Other Animation Libraries

The table below outlines the positioning differences between AutoAnimate and other popular animation libraries to help you make an informed decision:

LibraryDesign PhilosophyBest ForPain Points
AutoAnimate"It just works"
Zero-config layout transitions based on DOM mutations.
Lists & Toggles
Simple UI polish like dropdowns, accordions, and lists.
Customization
Hard to fine-tune timing or create complex, multi-stage sequences.
Framer MotionDeclarative Powerhouse
Production-ready motion library for React with comprehensive control.
Complex UI
Orchestration, gestures, shared layout animations, and 3D.
Bundle Size
Significantly larger; overkill for simple list transitions.
React Transition GroupLifecycle Hooks
Exposes enter/exit stages for you to apply CSS classes.
Legacy Support
Projects that rely heavily on CSS for animation definitions.
Boilerplate
Requires verbose setup and manual CSS writing for every transition.

Verdict: When to Adopt

AutoAnimate is the best choice for 90% of standard UI interactions—like opening a dropdown, sorting a list, or switching tabs—where you want the interface to feel premium without spending hours tweaking easing curves. If you are building a highly interactive marketing site or a complex dashboard with orchestrated motion, look towards Framer Motion. For everything else, start here.