Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 37 ยท Animation and Advanced Features

Keyframe Animations in Tailwind CSS

Use Tailwind CSS built-in animations (spin, ping, pulse, bounce) and define your own @keyframes inside @theme to build loaders, skeletons, wiggles and attention effects.

A transition goes from one state to another when something changes. A keyframe animation runs by itself: it can loop, have many steps and start as soon as the element appears. Tailwind ships four ready-made animations and lets you add your own in the @theme block, together with their @keyframes, so the animation becomes a normal utility such as animate-wiggle.

The built-in animations

Utility Effect Typical use
animate-spin continuous 360-degree rotation loading spinners
animate-ping scales up and fades out repeatedly notification dots
animate-pulse gentle fade in and out skeleton placeholders
animate-bounce bounces up and down scroll-down hints
animate-none removes animation overriding at a breakpoint or state
The four built-in animations

The ping dot is built from two spans: the outer one scales and fades, while the inner one stays still, giving a "radar" effect. The skeleton uses animate-pulse on a wrapper, so all gray bars pulse together.

Defining your own animation

An animation has two parts: the keyframes (what happens) and the animation shorthand (name, duration, timing, repeat). In v4 you declare both in @theme, so Tailwind generates animate-<name> and includes the @keyframes only when you use it.

CSS
@theme {
  --animate-wiggle: wiggle 0.6s ease-in-out infinite;

  @keyframes wiggle {
    0%, 100% { transform: rotate(-4deg); }
    50% { transform: rotate(4deg); }
  }
}

The variable name after --animate- becomes the utility name, and the value is an ordinary animation shorthand referring to the @keyframes rule.

Custom wiggle and fade-up animations

Because animate-wiggle is a real utility, hover:animate-wiggle works without extra code. The staggered list uses an arbitrary property [animation-delay:150ms]. The both fill mode in the animation keeps the first keyframe applied during the delay, so the items stay invisible until their turn.

Controlling an animation

The animation utilities set the whole shorthand, so you shape it by overriding with arbitrary values or by writing the shorthand yourself:

  • Different speed or count: animate-[wiggle_1s_ease-in-out_3] (wiggle for 1 s, three times).
  • Pause on hover: hover:[animation-play-state:paused].
  • Stop for users who prefer less motion: motion-reduce:animate-none.
  • Delay: [animation-delay:200ms].

You can also change the built-ins by redeclaring them: --animate-spin: spin 2s linear infinite; makes every animate-spin slower.

Real examples

A button spinner while loading. The classic loading state is a disabled button with a spinner:

Submit button with a spinner

A marquee ticker. A looping horizontal slide needs a custom keyframe and a duplicated list:

A marquee with a custom keyframe

The list is repeated twice and moves by exactly half of its own width, so when the loop restarts the content looks identical, which hides the jump. The hover: pause makes it readable.

Good motion habits

  • Animations that loop forever should be small and calm; decorative ones should be removable with motion-reduce:animate-none.
  • Never rely on animation to carry meaning. A spinner should be accompanied by text such as "Saving", or by aria-busy.
  • Spin and pulse animations are cheap (opacity and transform). Avoid animating box-shadow or layout properties in loops.
  • Many animated elements can hurt battery on phones; prefer one animated wrapper over fifty animated children.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which utility is intended for skeleton loading placeholders?

    animate-pulse softly fades an element in and out, the standard skeleton effect.
  2. 2. Where do you define a custom animation and its keyframes in Tailwind v4?

    The --animate-* namespace creates the utility, and @keyframes inside @theme supplies the steps.
  3. 3. How do you pause an animation on hover?

    An arbitrary property is the way to set animation-play-state.
  4. 4. Which class turns off an animation for users who asked for reduced motion?

    motion-reduce: matches prefers-reduced-motion: reduce.

Summary

  • The built-ins are animate-spin, animate-ping, animate-pulse and animate-bounce; animate-none removes them.
  • Add your own with --animate-name: ... and a @keyframes rule inside @theme; it becomes animate-name, and works with variants.
  • Tune speed, delay, count and play state with arbitrary values, and always offer motion-reduce:animate-none.

Next: Filters, Gradients and Masks