Sub topic 3
Setting duration and delay
This chapter assumes you know basic HTML and CSS, are comfortable with Tailwind utility classes, and have a rough idea of what a CSS transition is. It covers the duration-* and delay-* utilities, which control how long a transition runs and when it starts.
What duration and delay control
A transition has two timing values that are easy to confuse.
- Duration is how long the change takes from start to finish. It maps to
transition-duration. - Delay is how long the browser waits after the trigger before the change starts. It maps to
transition-delay.
Both only matter when a transition is active. If an element has no transition, transition-colors or similar utility, setting duration-300 has no visible effect, because there is nothing to time.
Duration utilities
Tailwind provides a scale of duration-* classes in milliseconds.
| Class | Value |
|---|---|
| `duration-75` | 75ms |
| `duration-100` | 100ms |
| `duration-150` | 150ms |
| `duration-200` | 200ms |
| `duration-300` | 300ms |
| `duration-500` | 500ms |
| `duration-700` | 700ms |
| `duration-1000` | 1000ms |
The transition utilities set a default duration of 150ms. You only need a duration-* class when you want something different.
<button class="rounded bg-indigo-600 px-4 py-2 text-white transition-colors duration-200 ease-out hover:bg-indigo-700">
Save
</button>Here the background color change takes 200ms. Without duration-200, it would take the default 150ms.
Choosing a duration
Short durations feel responsive. Long ones feel deliberate, and they can feel sluggish when they follow a user action.
- 75ms to 150ms suits small color changes on buttons and links.
- 200ms to 300ms suits most hover and focus effects, such as a card lift.
- 500ms and above suits large movements or attention-drawing effects. Use these sparingly.
A common mistake is making every transition slow. Users notice a button that takes 500ms to respond to a hover.
Delay utilities
The delay-* classes use the same style of scale.
<div class="rounded-lg bg-white p-6 shadow transition duration-300 delay-150 hover:shadow-lg">
Card content
</div>The shadow waits 150ms after the pointer enters, then grows over 300ms. The delay also applies when the pointer leaves, because the base classes carry the same delay in both directions.
Different timing in each direction
State variants can set timing separately for the entering and leaving direction. Put the timing class on the variant to apply it only in that state.
<div class="rounded bg-slate-100 p-4 transition-opacity duration-500 hover:duration-100 hover:delay-0">
Hover me
</div>The base classes apply when the pointer leaves, so the fade back takes 500ms. The hover: classes apply while the pointer is over the element, so the change in that direction takes 100ms with no delay. This pattern gives a quick response and a gentle release.
Staggering with delay
Delay is the usual way to stagger a list so items change one after another.
<ul class="flex gap-2">
<li class="size-4 rounded-full bg-indigo-600 motion-safe:animate-bounce"></li>
<li class="size-4 rounded-full bg-indigo-600 motion-safe:animate-bounce [animation-delay:150ms]"></li>
<li class="size-4 rounded-full bg-indigo-600 motion-safe:animate-bounce [animation-delay:300ms]"></li>
</ul>For keyframe animations, delay-* sets transition-delay, not animation-delay. The arbitrary property syntax [animation-delay:150ms] sets the animation delay directly.
Arbitrary values
If the scale does not have the value you want, use square brackets.
<div class="transition-transform duration-[400ms] delay-[80ms] hover:scale-105">
Custom timing
</div>In Tailwind v4 you can also write duration-400 and delay-80, because numeric values are generated on demand. In v3, use brackets or extend the theme.
Common errors
- No effect from
duration-*. The element has notransition*utility. Add one. - Delay on both directions. A delay on the base state also delays the return. Move it to the variant if you only want it on hover.
- Everything is slow. Long durations stack up when several elements transition. Start at 150ms to 300ms and adjust.
Exercise
A card has the classes transition duration-500 hover:shadow-lg. Users say it feels slow when the pointer enters. Which change gives a fast response on hover but keeps a slow fade back when the pointer leaves, and why does it work?
Show answer
Add hover:duration-150. The hover: class applies only while the pointer is over the card, so the shadow grows in 150ms. When the pointer leaves, the hover variant stops matching and the base duration-500 applies, so the shadow fades out over 500ms.