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 |
<!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) setstransition-behavior: allow-discrete, which lets the browser transition elements that switch betweenhiddenandblock. 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:
<!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 |
<!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:
<!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?
animate-pulsetransition-colors duration-300delay-300ease-in
Which built-in animation is commonly used for skeleton loading placeholders?
animate-spinanimate-pinganimate-pulseanimate-bounce
How do you add an animate-wiggle utility in v4?
- Add
wiggletotailwind.config.jsplugins - Define
--animate-wiggleand its@keyframesinside@theme - Write
.animate-wiggle {}in a<script> - It is built in