Duration and timing curves control how long animations take and how they speed up or slow down. This makes animations feel smooth and natural.
Duration and timing curves in Tailwind
transition duration-[time] ease-[function]
Use duration-[time] to set how long the animation lasts, like duration-500 for 500ms.
Use ease-[function] to control the speed curve, like ease-in-out for smooth start and end.
transition duration-300 ease-in
transition duration-700 ease-out
transition duration-500 ease-in-out
transition duration-1000 linear
This page shows a blue button. When you hover over it, the background color changes smoothly over 700 milliseconds using an ease-in-out timing curve. This means the color change starts slow, speeds up in the middle, and slows down at the end, making the effect feel natural.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Tailwind Duration and Timing Curves</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="flex items-center justify-center min-h-screen bg-gray-100"> <button class="bg-blue-600 text-white px-6 py-3 rounded transition duration-700 ease-in-out hover:bg-blue-400"> Hover me </button> </body> </html>
Use shorter durations for quick feedback and longer durations for noticeable effects.
Timing curves like ease-in, ease-out, and ease-in-out help make animations feel more natural than a constant speed.
Test animations on different devices to ensure they feel smooth everywhere.
Duration controls how long an animation takes.
Timing curves control the speed pattern of the animation.
Tailwind makes it easy to add these with simple classes like duration-500 and ease-in-out.
Practice
duration-700 control in an animation?Solution
Step 1: Understand the purpose of duration classes
In Tailwind, duration classes likeduration-700set how long an animation runs in milliseconds.Step 2: Identify what
The number 700 means 700 milliseconds, so the animation takes 0.7 seconds to finish.duration-700meansFinal Answer:
The length of time the animation takes to complete -> Option DQuick Check:
Duration controls animation time = B [OK]
- Confusing duration with delay
- Thinking duration changes color or size
- Mixing duration with timing curve
Solution
Step 1: Recall Tailwind timing curve class names
Tailwind uses simple class names likeease-in,ease-out, andease-in-outto set timing curves.Step 2: Identify the correct class for ease-in-out
The correct class is exactlyease-in-out. Other options are invalid or do not exist.Final Answer:
ease-in-out -> Option AQuick Check:
Timing curve class = ease-in-out = D [OK]
- Adding extra prefixes like duration- or timing-
- Using animate- prefix incorrectly
- Confusing timing curve with duration
duration-300 ease-linear?Solution
Step 1: Understand duration-300 meaning
The classduration-300sets the animation length to 300 milliseconds (0.3 seconds).Step 2: Understand ease-linear timing curve
ease-linearmeans the animation speed is constant from start to end, no acceleration or slowing.Final Answer:
300 milliseconds with a constant speed -> Option BQuick Check:
duration-300 + ease-linear = 300ms constant speed [OK]
- Confusing milliseconds with seconds
- Thinking ease-linear means slow start
- Believing ease-linear is invalid
class="duration-500 ease-inout" but the animation speed is not smooth. What is the error?Solution
Step 1: Check the timing curve class spelling
The correct Tailwind class for this timing curve isease-in-outwith dashes between words.Step 2: Understand why
Without dashes, Tailwind does not recognize the class, so no timing curve is applied, causing animation issues.ease-inoutfailsFinal Answer:
The class should beease-in-outwith dashes -> Option AQuick Check:
Correct timing curve class = ease-in-out [OK]
- Missing dashes in timing curve class
- Using wrong units for duration
- Adding unnecessary prefixes
Solution
Step 1: Identify the needed animation duration
The animation should last 1 second, soduration-1000(1000 milliseconds) is correct.Step 2: Choose the timing curve for slow start and end
ease-in-outtiming curve starts slow, speeds up in the middle, then slows down at the end, matching the requirement.Final Answer:
duration-1000 ease-in-out -> Option CQuick Check:
1s duration + ease-in-out curve = A [OK]
- Choosing too short duration
- Using ease-linear which is constant speed
- Using only ease-in or ease-out which don't slow both ends
Ready to prove it?
Pass the test and this pattern moves unknown
