All Posts

How to use transitions in Tailwind CSS

You know what makes the difference between a static website and one that feels polished? Transitions.

Those smooth animations when you hover over a button, when a modal slides into view, or when colors shift on interaction. They're everywhere in modern web design, and for good reason.

Tailwind CSS gives you all the tools to add these smooth transitions without writing a single line of custom CSS. Let me show you how it works.

Starting with the basics

At its core, a transition needs two things: which properties should animate, and how long the animation should take.

Tailwind gives you the transition class as your starting point. Pop it on any element and it'll smoothly animate changes to common properties like colors, shadows, and transforms.

<button class='bg-blue-500 text-white px-6 py-3 rounded-lg transition hover:bg-blue-700'>
  Hover me
</button>

See how the background color smoothly fades from one blue to another? That's the transition class doing its magic. Without it, the color would just snap to the new value instantly.

Controlling which properties transition

Sometimes you don't want everything to transition. Maybe you only want colors to animate, or just opacity changes.

Tailwind has specific classes for this:

  • transition-colors - Only transitions color properties
  • transition-opacity - Only transitions opacity
  • transition-transform - Only transitions transforms like scale and rotate
  • transition-all - Transitions everything (use sparingly, can hurt performance)

Here's a practical example showing the difference:

<div class='space-y-4'>
  <button class='bg-green-500 text-white px-6 py-3 rounded-lg transition-colors hover:bg-green-700 hover:scale-110'>
    Colors Only
  </button>

  <button class='bg-purple-500 text-white px-6 py-3 rounded-lg transition-transform hover:bg-purple-700 hover:scale-110'>
    Transform Only
  </button>

  <button class='bg-pink-500 text-white px-6 py-3 rounded-lg transition-all hover:bg-pink-700 hover:scale-110'>
    All Properties
  </button>
</div>

The first button only animates its color change. The scale happens instantly. The second button does the opposite. And the third button animates both smoothly.

Adjusting transition duration

The default transition speed is 150 milliseconds. Sometimes that's too fast, sometimes too slow.

You can control the speed with duration classes: duration-75, duration-100, duration-150, duration-200, duration-300, duration-500, duration-700, and duration-1000.

The number represents milliseconds, so duration-500 means half a second.

<div class='flex gap-4 flex-wrap'>
  <button class='bg-blue-500 text-white px-4 py-2 rounded transition duration-75 hover:bg-blue-700'>
    Fast (75ms)
  </button>

  <button class='bg-blue-500 text-white px-4 py-2 rounded transition duration-300 hover:bg-blue-700'>
    Medium (300ms)
  </button>

  <button class='bg-blue-500 text-white px-4 py-2 rounded transition duration-1000 hover:bg-blue-700'>
    Slow (1000ms)
  </button>
</div>

Hover over each button and feel the difference. The fast one snaps quickly, the slow one takes its time. Most of the time you'll want something in the 200-500ms range.

Making transitions feel natural with easing

Duration isn't everything. The way something speeds up and slows down during the transition matters too. That's called easing.

Tailwind gives you these easing options:

  • ease-linear - Constant speed throughout
  • ease-in - Starts slow, ends fast
  • ease-out - Starts fast, ends slow
  • ease-in-out - Starts slow, speeds up, slows down at the end
<div class='space-y-4 max-w-2xl'>
  <div class='bg-gray-200 p-4 rounded-lg'>
    <div class='size-16 bg-red-500 rounded transition-transform duration-700 ease-linear hover:translate-x-64'></div>
    <p class='text-sm text-gray-600 mt-2'>Linear - constant speed</p>
  </div>

  <div class='bg-gray-200 p-4 rounded-lg'>
    <div class='size-16 bg-blue-500 rounded transition-transform duration-700 ease-in hover:translate-x-64'></div>
    <p class='text-sm text-gray-600 mt-2'>Ease In - starts slow</p>
  </div>

  <div class='bg-gray-200 p-4 rounded-lg'>
    <div class='size-16 bg-green-500 rounded transition-transform duration-700 ease-out hover:translate-x-64'></div>
    <p class='text-sm text-gray-600 mt-2'>Ease Out - ends slow</p>
  </div>

  <div class='bg-gray-200 p-4 rounded-lg'>
    <div class='size-16 bg-purple-500 rounded transition-transform duration-700 ease-in-out hover:translate-x-64'></div>
    <p class='text-sm text-gray-600 mt-2'>Ease In Out - smooth acceleration</p>
  </div>
</div>

Hover over each box and watch how they move differently. Most UI transitions feel best with ease-out or ease-in-out because they feel more natural.

Adding delays to create sequences

Sometimes you want a slight pause before the transition starts. Maybe you're creating a staggered animation effect, or you want to avoid accidental triggers.

Use delay classes: delay-75, delay-100, delay-150, delay-200, delay-300, delay-500, delay-700, and delay-1000.

<div class='flex gap-4 flex-wrap'>
  <div class='size-20 bg-red-500 rounded transition-all duration-500 hover:scale-125 hover:bg-red-700 flex items-center justify-center text-white text-xs font-semibold'>
    No delay
  </div>

  <div class='size-20 bg-blue-500 rounded transition-all duration-500 delay-150 hover:scale-125 hover:bg-blue-700 flex items-center justify-center text-white text-xs font-semibold'>
    150ms
  </div>

  <div class='size-20 bg-green-500 rounded transition-all duration-500 delay-300 hover:scale-125 hover:bg-green-700 flex items-center justify-center text-white text-xs font-semibold'>
    300ms
  </div>

  <div class='size-20 bg-purple-500 rounded transition-all duration-500 delay-500 hover:scale-125 hover:bg-purple-700 flex items-center justify-center text-white text-xs font-semibold'>
    500ms
  </div>
</div>

Hover over each box. Notice how the later boxes wait a bit before starting their transition. This creates a nice cascading effect when used on multiple elements.

Real world examples

Let me show you some practical patterns you'll use all the time.

Card hover effects:

<div class='max-w-sm bg-white rounded-lg shadow-lg overflow-hidden transition-all duration-300 hover:shadow-2xl hover:-translate-y-2'>
  <div class='w-full h-48 bg-gradient-to-br from-blue-400 to-purple-500'></div>
  <div class='p-6'>
    <h3 class='text-xl font-bold text-gray-800 mb-2'>Product Card</h3>
    <p class='text-gray-600'>Hover over this card to see the smooth lift effect with enhanced shadow.</p>
  </div>
</div>

Button with multiple transition effects:

<div class='flex justify-center'>
  <button class='bg-gradient-to-r from-cyan-500 to-blue-500 text-white font-semibold px-8 py-4 rounded-full transition-all duration-300 hover:from-cyan-600 hover:to-blue-600 hover:shadow-xl hover:scale-105 active:scale-95'>
    Click me
  </button>
</div>

Toggle switch with transitions:

<div class='flex justify-center items-center'>
  <label class='relative inline-block w-14 h-8 cursor-pointer'>
    <input type='checkbox' class='sr-only peer'>
    <div class='w-14 h-8 bg-gray-300 rounded-full peer-checked:bg-green-500 transition-colors duration-300'></div>
    <div class='absolute left-1 top-1 size-6 bg-white rounded-full transition-transform duration-300 peer-checked:translate-x-6 shadow-md'></div>
  </label>
</div>

Custom transition values

Need a specific duration or timing that Tailwind doesn't provide? Use arbitrary values with bracket notation.

For a 2-second transition: duration-[2000ms] or duration-[2s]

For a custom cubic-bezier curve: ease-[cubic-bezier(0.95,0.05,0.795,0.035)]

<div class='flex justify-center items-center h-full'>
  <button class='bg-orange-500 text-white px-6 py-3 rounded-lg transition-all duration-[2s] ease-[cubic-bezier(0.68,-0.55,0.265,1.55)] hover:scale-150 hover:rotate-12'>
    Custom transition
  </button>
</div>

This button has a bouncy 2-second animation with a custom easing curve. Pretty wild, right?

Respecting user preferences

Some people get motion sick from animations. Browsers let users indicate they prefer reduced motion, and Tailwind respects that.

Use the motion-reduce: prefix to provide alternative styles:

<div class='flex justify-center'>
  <button class='bg-indigo-500 text-white px-6 py-3 rounded-lg transition-all duration-500 hover:scale-110 motion-reduce:transition-none motion-reduce:hover:scale-100'>
    Accessible button
  </button>
</div>
<p class='text-center text-sm text-gray-600 mt-4'>This button respects prefers-reduced-motion setting</p>

Users with motion sensitivity won't see the scaling animation, but the button still works perfectly.

And there you have it. Transitions in Tailwind CSS are straightforward once you understand the pieces: which properties to animate, how long it should take, the easing curve, and any delay.

Start simple with the transition class and build from there. Your interfaces will feel so much more polished with just a few utility classes.

Play around with the examples, mix and match different durations and easing functions, and you'll quickly develop an intuition for what feels right.

Happy coding!

Other posts you might like...

See more

Subscribe to our newsletter

Get notified when we add new templates, components, and more!

Thanks for subscribing!
Please check your email to confirm your subscription.

WindyBase Make development a breeze

WindyBase is a weekly curated Tailwind CSS template and tool directory built for the modern developer.

© 2026 WindyBase. All rights reserved.