Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 37 ยท Typography, Color and Effects

Transitions and Transforms

Animate state changes in Tailwind v4: transition properties, duration, easing and delay, plus scale, rotate, translate, 3D transforms and reduced-motion support.

Small movements make an interface feel alive: a button that lifts when you hover it, a chevron that rotates when a menu opens, a card that eases in. Tailwind splits this into two ideas. Transitions say how a property changes from one value to another (how long, with what easing). Transforms move, scale and rotate an element without disturbing the layout around it. You combine them: the transform changes on hover, and the transition makes the change smooth.

Transitions

Without a transition, a hover color change is instant. Add transition to the element (not to the hover variant) and the change animates:

HTML
<button class="bg-indigo-600 hover:bg-indigo-700 transition">Save</button>

transition animates a sensible list of properties: colors, opacity, shadow, transform and filters. Narrow it to be precise and cheaper:

Class Animates
transition common properties (colors, opacity, shadow, transform, filter)
transition-colors color, background-color, border-color, fill, stroke
transition-opacity opacity
transition-shadow box-shadow
transition-transform transform properties
transition-all every property (use rarely; it can animate things you did not intend)
transition-none no transition

Tune it with:

  • Duration: duration-75, duration-150 (the default), duration-200, duration-300, duration-500, duration-700, duration-1000. UI feedback feels best between 150 and 300 ms.
  • Easing: ease-linear, ease-in, ease-out, ease-in-out. ease-out suits things appearing (fast start, soft landing), ease-in suits things leaving. In v4 you can also define your own in the theme, or write ease-[cubic-bezier(.2,.8,.2,1)].
  • Delay: delay-100, delay-300, and so on, to stagger items.

Transforms

v4 uses the modern individual CSS properties scale, rotate and translate, so these utilities no longer need the transform class (it was required in v2 and earlier):

Class Effect
scale-95, scale-110, scale-x-125 resize by percentage
rotate-6, -rotate-3, rotate-180 rotate in degrees
translate-x-4, -translate-y-1, translate-x-1/2 move (uses the spacing scale and fractions of its own size)
skew-x-6 skew
origin-center, origin-top-left, origin-bottom pivot point

Because transforms do not affect layout, other elements do not move. Combine them for the classic lift: hover:-translate-y-1 hover:shadow-lg.

Hover transitions

Notice each card sets transition on the normal state and the change on hover:. This also means the transition plays on the way back when you move the pointer off, which is exactly what you want.

group and peer: moving a child on parent hover

group marks a parent, and group-hover: styles a child when the parent is hovered. This is how arrows slide on buttons and images zoom inside cards:

HTML
<a href="#" class="group flex items-center gap-2">
  Read more
  <svg class="size-4 transition group-hover:translate-x-1">...</svg>
</a>

peer does the same for siblings (peer-checked:), which you will use for custom checkboxes and toggles. Both belong to chapter 5.

A toggle with a rotating icon

Transitions also animate class changes from JavaScript. The chevron below rotates when the panel opens, because adding rotate-180 changes the transform and the transition smooths it:

Accordion with a rotating chevron

The panel uses a well-known trick: animating a grid row from 0fr to 1fr opens a section to its natural height, something height: auto could never animate. The transition-[grid-template-rows] class is an arbitrary value (see Arbitrary Values). All four classes written in the JavaScript appear in full in the source, so a real build finds them.

3D transforms

v4 adds 3D utilities: rotate-x-45, rotate-y-12, translate-z-8, scale-z-110 and a perspective-* family (perspective-near, perspective-distant, perspective-[800px]), plus transform-3d to let children share the 3D space and backface-hidden. They are enough for a card flip or a tilted mockup:

HTML
<div class="perspective-distant">
  <div class="transform-3d rotate-x-12 rotate-y-12 ...">Tilted card</div>
</div>

Respect reduced motion

Some people get dizzy or distracted from motion, and operating systems let them say so. Use the motion-safe: and motion-reduce: variants so animation only plays for users who have not asked for less:

HTML
<div class="motion-safe:transition motion-safe:hover:scale-105">...</div>
<div class="animate-spin motion-reduce:animate-none">...</div>

A good rule: color and opacity changes are always fine; large movements, parallax and constant looping should be skipped under motion-reduce:.

Performance tips

  • Animate transform and opacity: they are cheap because the browser does not need to re-layout the page. Animating width, height, margin or top triggers layout every frame.
  • Avoid transition-all except in prototypes.
  • Keep durations short. 150-300 ms feels responsive; over 500 ms feels slow for UI feedback.
  • Elements that animate constantly can use will-change-transform, but only where you measured a benefit.

You have completed the foundation: you can set up Tailwind, space, size, lay out and decorate any page. The next chapters cover responsive design, state variants, dark mode, reuse and animation. Keep the Tailwind CSS track overview handy.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Where do you put the transition class?

    The transition is a property of the element itself, so it animates the change in both directions.
  2. 2. Which properties are the cheapest to animate?

    Transform and opacity do not trigger layout, so they animate smoothly even on slow devices.
  3. 3. What does group-hover: do?

    Add group to the parent; group-hover:* on a descendant then applies while the parent is hovered.
  4. 4. Which variant disables an animation for users who prefer less motion?

    motion-reduce: matches prefers-reduced-motion: reduce. motion-safe: is the opposite.
  5. 5. In v4, how do scale-105 and rotate-3 apply?

    v4 emits the modern individual transform properties, so the old transform class is unnecessary.

Summary

  • transition (or a specific one such as transition-colors) plus duration-*, ease-* and delay-* animates changes.
  • scale-*, rotate-*, translate-* and skew-* transform without affecting layout; v4 adds 3D utilities.
  • group-hover: moves children when the parent is hovered; JavaScript class toggles animate too.
  • Animate transform and opacity, keep durations short, and honor motion-reduce:.

Next: Responsive Design with Breakpoints