Lesson 39 of 52Tailwind in practice
Tailwind Transitions and Animation
Add motion with Tailwind: transition, duration and easing utilities, transforms, built-in and custom animations, enter effects with starting:, and reduced motion.
Good motion is mostly invisible. A button that darkens over 150 milliseconds instead of snapping, a card that lifts a few pixels when you point at it, a spinner that tells you something is happening: none of these are decoration, they are feedback. You learned how transitions, transforms and keyframes work in plain CSS in the animations lesson. This lesson shows how Tailwind turns all of it into short classes, how to add your own animations to the theme, how to animate elements as they appear with starting:, and how to keep everything fast and kind to people who prefer less motion.
The transition utilities
A transition needs three things: which properties to smooth, how long it takes, and how the speed changes along the way (the easing). Tailwind gives each its own class.
| Class | What it sets |
|---|---|
transition | The common properties: colours, opacity, shadows, transforms, filters. 150ms with a gentle ease by default |
transition-colors | Only colour properties: text, background, border, outline, fill, stroke |
transition-opacity | Only opacity |
transition-transform | Only movement, scaling and rotation |
transition-shadow | Only box-shadow |
transition-all | Every property that can animate |
transition-none | No transition |
duration-300 | transition-duration: 300ms. Any number works in version 4 |
ease-out, ease-in, ease-in-out, ease-linear | The timing function |
delay-150 | Wait 150ms before starting |
Two habits follow from the plain CSS lesson. First, put the transition classes on the element without a variant, so the change animates in both directions; hover:transition would fade in and snap back. Second, prefer a specific class like transition-colors over transition-all, so you animate only what you meant to, and a layout change elsewhere does not start sliding around.
Preview
Move the pointer across the three buttons. 75ms feels instant but smooth; 700ms feels sluggish for something as small as a button. Most interface transitions sit between 100ms and 300ms. The card shows the classic hover lift: hover:-translate-y-1 raises it 4px (the minus sign makes it negative, so upwards), while hover:shadow-lg and hover:ring-2 make it feel closer. Notice the same lift is repeated on focus-visible:, so keyboard users get the same feedback. Try hover:scale-[1.02] instead of the lift.
A few rules of thumb for picking values. Small things change fast: colour on a button or link, 100ms to 150ms. Medium things, like a card lifting or a menu opening, take 200ms to 300ms. Big movements across the screen, such as a drawer sliding in, can take up to about 400ms. Use ease-out for things entering or reacting to the user, because they start quickly and settle gently, and ease-in for things leaving. Shadows and rings are a good way to suggest depth on hover, but keep them subtle, and remember that ring-* draws with box-shadow, so it animates with transition or transition-shadow.
How long, in milliseconds, does the colour change take on hover? Type a number.
<button class="transition-colors delay-100 duration-200 hover:bg-sky-500">
Transforms
Transforms move, resize or rotate an element without affecting the layout around it. Neighbours stay where they are, which is exactly why transforms are cheap to animate.
- Translate:
translate-x-4,-translate-y-1,translate-y-full,-translate-x-1/2. Uses the spacing scale, fractions or arbitrary values. - Scale:
scale-95,scale-105,scale-x-0. The number is a percentage. - Rotate:
rotate-3,-rotate-6,rotate-90,rotate-[17deg]. - Origin:
origin-left,origin-top-rightset the point the element scales or rotates around.
In version 4 these use the CSS translate, scale and rotate properties, so you can combine them freely without a separate transform class. Delays let you stagger several items so they move one after another.
Preview
The tile rotates and grows, the bars grow from their left edge one after another, and the arrow nudges right. Change origin-left to origin-right on the bars, or remove the delays to see how much the stagger adds.
Built-in animations
Transitions need a trigger. Animations run on their own. Tailwind ships four, each a keyframe animation:
| Class | What it does | Typical use |
|---|---|---|
animate-spin | Rotates 360 degrees, forever, at constant speed | Loading spinners |
animate-ping | Scales up and fades out, like a ripple | Notification dots, "live" badges |
animate-pulse | Fades gently in and out | Skeleton loaders |
animate-bounce | Bounces up and down | "Scroll down" hints |
A skeleton loader is a grey outline of the content that is coming, shown while it loads. It feels faster than a blank screen or a lone spinner because the page already has its shape.
Preview
Each animation has a motion-reduce: fallback. The ping ripple is hidden completely for reduced motion while the solid dot stays, so the meaning ("online") survives. The skeleton is marked aria-busy="true" and carries a sr-only label, because screen readers cannot see grey bars. Change w-3/4 to w-full to reshape the skeleton to match your real content.
Match each built-in animation to its best use.
Custom animations in @theme
For anything else, add your own. In version 4 an animation is a theme variable in the --animate-* namespace, and its @keyframes can live right inside the same @theme block. That gives you an animate-wiggle class that works with variants like any other.
Preview
The list items rise in one after another when the preview loads; edit any character to replay them. both in --animate-rise keeps the first keyframe applied during the delay, so the later items do not flash before they start. The delay-* utilities only set transition-delay, so the stagger uses arbitrary properties like [animation-delay:120ms]. The third button uses a custom easing token: --ease-snappy creates ease-snappy, and its last number above 1 makes it overshoot slightly. Try making wiggle run infinite times instead of 2, and you will see why looping motion should be rare.
Enter animations with starting:
There is one moment a normal transition cannot catch: when an element first appears. It has no previous style to transition from, so it just pops in. The CSS @starting-style rule fixes that by declaring the style an element starts from on its first frame, and Tailwind exposes it as the starting: variant.
JavaScript adds a new element to the page.
Preview
Click the button a few times and each message slides up and fades in. Remove the two starting: classes and they just appear. @starting-style is supported in current versions of all major browsers, but it arrived during 2024, so check Can I Use if you support older ones; browsers without it simply show the element with no animation, which is a safe fallback. For elements that toggle display (a dialog or a popover), Tailwind's docs pair starting:open: with transition-discrete so the hidden state can animate too; read the starting and transition-behavior sections there before you build one. Also note the class list lives in the script as a full string, so a real Tailwind build can still find it.
Performance and reduced motion
Two rules keep motion smooth and respectful.
Animate transform and opacity. As the plain CSS lesson showed, these can skip layout and paint. In Tailwind terms: reach for translate-*, scale-*, rotate-* and opacity-*, not w-*, h-*, top-* or m-*. Colour and shadow transitions are fine on small elements. will-change-transform hints that an element will move, but add it only when you have measured a problem.
Respect prefers-reduced-motion. Some people get dizzy or nauseous from movement and switch it off in their system settings. motion-safe: applies only when they have not, and motion-reduce: applies only when they have.
The base layer sits on the element with no variant, so the change animates both ways.
Choose between the two styles by what is safer to forget. motion-safe:animate-rise is opt-in: motion only exists when it is allowed. motion-reduce:animate-none is opt-out: handy when adding to existing classes. To test, open Chrome devtools, find the Rendering panel in the command menu, and emulate prefers-reduced-motion: reduce. The page must still make complete sense with every animation off.
Put these steps for adding a hover lift to a card in order.
- Tap the steps below in the right order.
transition-all duration-300 h-0 open:h-64. What is the best change?- transition
- A smooth change between two values of a property, triggered by a state change like hover.
- duration
- How long a transition takes, set with classes like
duration-200. - easing
- How speed changes during a transition, such as
ease-out(fast start, slow finish). - transform
- Moving, scaling or rotating an element without changing the layout around it.
- skeleton loader
- Grey placeholder shapes that show the layout of content while it loads.
- starting: variant
- Tailwind's wrapper for
@starting-style, the styles an element animates from when it first appears. - prefers-reduced-motion
- A user setting, read by
motion-safe:andmotion-reduce:, that asks for less animation.