TExcelTAD
Home › Tailwind CSS › Transitions & Animation

Transitions & Animation

Motion makes interfaces feel responsive: a button that smoothly changes colour, a menu that fades in, a spinner while data loads. Tailwind gives you utilities for transitions (animate between two states) and animations (keyframe loops).

Transitions

A transition says which properties should animate and how long it takes. Then any state change — usually through hover: or focus: — animates instead of jumping.

Class Animates
transition colours, opacity, shadow, transforms, filters (the common set)
transition-colors colour, background, border, fill, stroke
transition-opacity opacity
transition-shadow box-shadow
transition-transform transforms (scale, rotate, translate)
transition-all every property (slower; use sparingly)
transition-none none
Class Controls
duration-150 / duration-300 / duration-700 length in ms (any number in v4)
ease-linear / ease-in / ease-out / ease-in-out timing curve
delay-100 / delay-500 wait before starting
html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="flex flex-wrap gap-4 p-6">
  <button class="rounded-lg bg-sky-500 px-4 py-2 text-white hover:bg-fuchsia-500">No transition</button>
  <button class="rounded-lg bg-sky-500 px-4 py-2 text-white transition-colors duration-500 hover:bg-fuchsia-500">transition-colors 500ms</button>
  <button class="rounded-lg bg-sky-500 px-4 py-2 text-white transition duration-300 ease-out hover:-translate-y-1 hover:shadow-xl">Lift on hover</button>
  <div class="flex size-20 items-center justify-center rounded-xl bg-amber-400 text-3xl transition-transform delay-200 duration-700 hover:rotate-180">⭐</div>
</body>
</html>

Note: transition-discrete (new in v4) sets transition-behavior: allow-discrete, which lets the browser transition elements that switch between hidden and block. You'll use it in the next example.

Entry animations with starting:

The starting: variant (CSS @starting-style, new in v4) sets the style an element starts from when it first appears, so it animates in without JavaScript timers:

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="p-6">
  <button id="show" class="rounded bg-gray-900 px-3 py-2 text-sm text-white">Show toast</button>
  <div id="toast" class="mt-4 hidden w-64 rounded-lg bg-emerald-600 p-3 text-white opacity-100 shadow-lg transition-all transition-discrete duration-500 starting:translate-y-4 starting:opacity-0">
    ✅ Saved successfully!
  </div>
  <script>
    document.getElementById('show').onclick = () => {
      document.getElementById('toast').classList.toggle('hidden');
    };
  </script>
</body>
</html>

Built-in animations

Class Effect Typical use
animate-spin rotates forever loading spinners
animate-ping grows and fades like a radar ping notification dots
animate-pulse gently fades in and out skeleton placeholders
animate-bounce bounces up and down "scroll down" arrows
animate-none stops animation
html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="flex flex-wrap items-center gap-10 p-8">
  <div class="size-10 animate-spin rounded-full border-4 border-sky-200 border-t-sky-600"></div>
  <span class="relative flex size-4">
    <span class="absolute inline-flex size-full animate-ping rounded-full bg-rose-400 opacity-75"></span>
    <span class="relative inline-flex size-4 rounded-full bg-rose-500"></span>
  </span>
  <div class="w-40 animate-pulse space-y-2">
    <div class="h-3 rounded bg-slate-300"></div>
    <div class="h-3 w-3/4 rounded bg-slate-300"></div>
    <div class="h-3 w-1/2 rounded bg-slate-300"></div>
  </div>
  <div class="animate-bounce text-3xl">⬇️</div>
</body>
</html>

Custom animations

Define your own in @theme with an --animate-* variable and put the @keyframes right inside the @theme block:

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
  <style type="text/tailwindcss">
    @theme {
      --animate-wiggle: wiggle 0.6s ease-in-out infinite;
      @keyframes wiggle {
        0%, 100% { transform: rotate(-8deg); }
        50% { transform: rotate(8deg); }
      }
    }
  </style>
</head>
<body class="flex items-center gap-6 p-8">
  <span class="animate-wiggle text-5xl">🔔</span>
  <span class="text-5xl hover:animate-wiggle">👋</span>
  <p class="text-sm text-gray-500">The bell always wiggles; the hand only on hover.</p>
</body>
</html>

Respecting reduced motion

Some people get dizzy from motion and set "reduce motion" in their OS. Use motion-safe: and motion-reduce: to respect that:

Class Applies when
motion-safe:animate-bounce the user has not asked for reduced motion
motion-reduce:transition-none the user has asked for reduced motion

Tip: Keep UI transitions short — 150–300ms feels snappy. Long durations make an interface feel sluggish.

Test yourself

A button has hover:bg-red-500 but the colour change is instant. What should you add?

  1. animate-pulse
  2. transition-colors duration-300
  3. delay-300
  4. ease-in

Which built-in animation is commonly used for skeleton loading placeholders?

  1. animate-spin
  2. animate-ping
  3. animate-pulse
  4. animate-bounce

How do you add an animate-wiggle utility in v4?

  1. Add wiggle to tailwind.config.js plugins
  2. Define --animate-wiggle and its @keyframes inside @theme
  3. Write .animate-wiggle {} in a <script>
  4. It is built in