Sub topic 3
Setting duration and delay
This chapter covers how long a transition runs and when it starts. It assumes you can write Tailwind utility classes, know what a CSS transition is, and have used a state variant such as hover: to trigger one. The chapter before this one introduced the transition-* property utilities. Here you control the clock.
The two timing properties
A CSS transition has four settings: which property changes, how long it takes, how it accelerates, and how long it waits before starting. Tailwind gives each one its own utility. This chapter covers two of them.
- Duration is how long the change takes from start to finish. Tailwind sets it with
duration-*, which maps totransition-duration. - Delay is how long the browser waits after the trigger before the change begins. Tailwind sets it with
delay-*, which maps totransition-delay.
Easing, the third setting, has its own chapter. For now, Tailwind's default easing is enough.
Why duration utilities do nothing alone
A common first mistake is adding duration-300 to an element and seeing no animation. The duration-* utilities only set the length of a transition. They do not start one. You also need a transition utility that names which properties animate.
<!-- Wrong: duration is set, but nothing is told to transition -->
<button class="bg-indigo-600 duration-300 hover:bg-indigo-700">Save</button>
<!-- Right: transition-colors selects the property, duration-300 sets the length -->
<button class="bg-indigo-600 transition-colors duration-300 hover:bg-indigo-700">Save</button>In Tailwind, the transition, transition-colors, transition-opacity, transition-shadow and transition-transform utilities each set a list of properties. They also set a default duration and timing function. Because duration-* is a separate utility, it overrides that default. The order of the classes in your HTML does not matter. Tailwind controls precedence in the generated stylesheet.
The duration scale
Tailwind's default scale uses milliseconds. The utilities are duration-75, duration-100, duration-150, duration-200, duration-300, duration-500, duration-700 and duration-1000. The number is the length in milliseconds, so duration-300 is 300 ms.
The transition utilities default to 150 ms. That is quick enough for a color change to feel instant while still looking smooth.
| Utility | Length | Typical use |
|---|---|---|
| `duration-75` | 75 ms | Press feedback, such as `active:` states |
| `duration-150` | 150 ms | Color changes on buttons and links (the default) |
| `duration-200` | 200 ms | Small movements, such as an arrow nudging sideways |
| `duration-300` | 300 ms | Cards lifting or scaling, dropdowns opening |
| `duration-500` | 500 ms | Larger panels, image fades |
| `duration-700` and `duration-1000` | 700 ms and 1 s | Decorative or attention-getting effects |
Here is a button that uses the scale from the spine's first example:
<button class="rounded bg-indigo-600 px-4 py-2 text-white transition-colors duration-200 ease-out hover:bg-indigo-700">
Save
</button>The hover:bg-indigo-700 variant triggers the change. transition-colors limits the animation to color properties. duration-200 makes it last 200 ms. ease-out is covered in the next chapter, so treat it as a given for now.
Choosing a good duration
Duration is a design decision. Too short, and the change reads as a flicker. Too long, and the interface feels sluggish.
- Small changes should be fast. A color shift on a button needs roughly 100 to 200 ms. Anything longer makes the control feel like it is lagging behind your cursor.
- Bigger changes can take longer. Moving or resizing a large element feels natural at 200 to 300 ms, because the eye needs time to follow the motion.
- Leaving can be quicker than entering. Users have already decided to move on, so an element that disappears at 150 ms feels more responsive than one that fades out at 300 ms.
- Be consistent. Pick two or three durations for the whole project and reuse them. Random values such as 170 ms and 230 ms in different places make an interface feel uneven.
Treat these as starting points and adjust by eye. The best test is to use the interface yourself.
Different durations in each direction
A transition uses the duration of the state it is moving into. This means you can set one duration on the base element and a different one on a variant, and the two directions will differ.
<div class="rounded-lg bg-white p-6 shadow transition duration-500 hover:-translate-y-1 hover:shadow-lg hover:duration-150">
Card content
</div>When the pointer enters the card, the hover state applies, so hover:duration-150 governs the change. The card lifts in 150 ms. When the pointer leaves, the hover state no longer applies, so the base duration-500 governs the return. The card settles back in 500 ms.
This is the reverse of what many people expect, so check it with a real example. If you want a snappy response followed by a slow release, put the short duration on the variant and the long one on the base. If you want the opposite, swap them.
Adding a delay
The delay-* utilities map to transition-delay. They use the same scale as durations: delay-75, delay-100, delay-150, delay-200, delay-300, delay-500, delay-700 and delay-1000.
A delay is useful in a few situations:
- Avoiding accidental triggers. A tooltip that appears after a short pause does not flash up when the pointer merely crosses the element.
- Sequencing. When several elements animate together, giving each a slightly larger delay produces a staggered effect.
- Letting one change finish first. A panel can wait for a background fade before its content appears.
Here is a tooltip-style example that waits before showing:
<div class="group relative inline-block">
<button class="rounded bg-slate-800 px-3 py-2 text-white">Help</button>
<span class="pointer-events-none absolute left-0 top-full mt-2 rounded bg-slate-900 px-2 py-1 text-sm text-white opacity-0 transition-opacity duration-150 group-hover:opacity-100 group-hover:delay-500">
Opens the help center
</span>
</div>The tooltip stays hidden for 500 ms after the pointer arrives, then fades in over 150 ms. On leaving, the group-hover: state no longer applies, so the base style applies. The base has no delay, and the tooltip fades out immediately. This shows the same direction rule as before: the delay in the target state is the one that counts. pointer-events-none stops the invisible tooltip from catching the pointer.
Staggering a list
Delays can be applied item by item. For a short, fixed list, write them directly:
<ul class="group flex gap-2">
<li class="size-8 rounded bg-indigo-500 opacity-40 transition-opacity duration-300 hover:opacity-100"></li>
<li class="size-8 rounded bg-indigo-500 opacity-40 transition-opacity delay-75 duration-300 hover:opacity-100"></li>
<li class="size-8 rounded bg-indigo-500 opacity-40 transition-opacity delay-150 duration-300 hover:opacity-100"></li>
</ul>Each square waits 75 ms longer than the one before it. Because the delay also applies when the pointer leaves (the base state carries it), each square fades back with the same offset. If you want a delay only on entry, put it on the variant, for example hover:delay-150, as in the tooltip.
Static class names matter here. Tailwind finds classes by scanning your source files for complete strings, so a class assembled in code, such as ` delay-${i * 75} `, will not be generated. Write out each full class name, or use a lookup table that contains the complete strings.
<!-- Works: the full class names appear in the source -->
<li class="delay-75"></li>
<li class="delay-150"></li>
<!-- Fails: Tailwind never sees "delay-75" or "delay-150" as complete strings -->
<li class="delay-{{ n }}"></li>Values outside the scale
If the scale does not have the value you want, Tailwind offers two options.
The first is an arbitrary value in square brackets. It works for one-off cases.
<div class="transition-opacity duration-[400ms] delay-[250ms] hover:opacity-50">Hover me</div>The second is a custom value, which suits values you will reuse. Tailwind v4 also accepts any whole number directly, so duration-250 produces 250 ms without extra setup. In v3, only the default values and ones you add in the config are available, so use an arbitrary value instead. Naming reusable durations in your theme is covered in a later chapter on theme customization.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| No animation at all | `duration-*` used without a `transition-*` utility | Add `transition`, `transition-colors` or another property utility |
| Change is instant on one direction only | The duration or delay was set only on the variant, so the return uses the base value | Set a duration on both the base and the variant |
| Delay applies on the way out as well as in | The delay is on the base element | Move the delay to the variant, for example `group-hover:delay-500` |
| A dynamic `delay-${n}` class has no effect | Tailwind could not see the full class name | Write the full class strings in the source |
| Some properties animate and others jump | The `transition-*` utility does not list those properties | Use `transition` for the default set, `transition-all`, or an arbitrary property list |
| Animation is much too slow or fast | A `duration-[...]` value was written without a unit | Include `ms` or `s` in arbitrary values |
How the timing fits together
The next diagram shows the order of events when a user hovers over an element that has both a delay and a duration.
The total time between the trigger and the finished state is the delay plus the duration. In the tooltip, that is 650 ms.
Interaction with other timing rules
- Changes that interrupt a transition. If the user moves away while a transition is running, the browser reverses from the current value. It does not jump to the start. The reverse uses the duration of the new target state.
- Multiple properties.
duration-*applies to every property in the transition list. If you need different lengths for different properties, use an arbitrarytransition-[...]list or write a custom property in CSS. - Reduced motion. Long durations matter most for users who are sensitive to motion. A later chapter covers
motion-safe:andmotion-reduce:, which let you shorten or remove timing for those users.
Exercise
A card has the classes transition duration-500 hover:-translate-y-1 hover:duration-100. How long does the card take to rise when the pointer enters, and how long to return when the pointer leaves? Explain why.
Show answer
It rises in 100 ms and returns in 500 ms. A transition uses the duration of the state it moves into. When the pointer enters, the hover state applies, so hover:duration-100 governs the rise. When the pointer leaves, the hover state no longer applies, so the base duration-500 governs the return.
Exercise
A button has bg-indigo-600 duration-300 hover:bg-indigo-700, but the color changes instantly on hover. What is missing, and what is the corrected class list?
Show answer
A transition utility that names the property to animate. duration-300 only sets the length. The corrected list is bg-indigo-600 transition-colors duration-300 hover:bg-indigo-700.
Exercise
You want a tooltip to appear 400 ms after the pointer enters its group, then fade in over 200 ms, and to disappear immediately when the pointer leaves. Which classes go on the tooltip to control timing and opacity?
Show answer
opacity-0 transition-opacity duration-200 group-hover:opacity-100 group-hover:delay-400. The delay sits on the group-hover: variant so it applies only on entry. The base has no delay, so the fade-out begins at once. In Tailwind v3, use group-hover:delay-[400ms] because delay-400 is not in the default scale.