📖 Scenario: You are creating a simple webpage with three colored boxes that animate by fading in one after another. You want to control the delay of each animation so they appear in sequence.
🎯 Goal: Build a webpage with three boxes that fade in with different delays using Tailwind CSS animation delay utilities.
📋 What You'll Learn
Use Tailwind CSS classes for animation and delay
Create three boxes with distinct background colors
Apply fade-in animation to each box
Set different animation delays for each box to appear one after another
Use semantic HTML and ensure accessibility
💡 Why This Matters
🌍 Real World
Animation delays are used in websites to create smooth, engaging visual effects that guide the user's attention.
💼 Career
Knowing how to control animation timing with Tailwind CSS is useful for frontend developers building interactive and polished user interfaces.
Progress0 / 4 steps
1
Create the HTML structure with three boxes
Create a <main> element with three <div> boxes inside it. Each box should have the classes h-24 and w-24 for height and width, and background colors bg-red-500, bg-green-500, and bg-blue-500 respectively.
Tailwind
Hint
Use three <div> elements inside <main> with the exact classes for size and background color.
2
Add the fade-in animation class
Add the Tailwind CSS animation class animate-fadeIn to each of the three boxes. You will define this animation in the next step.
Tailwind
Hint
Add the class animate-fadeIn to each box to prepare for the fade-in animation.
3
Configure animation delay classes
Add Tailwind CSS animation delay classes delay-0, delay-500, and delay-1000 to the red, green, and blue boxes respectively to create a staggered fade-in effect.
Tailwind
Hint
Use the classes delay-0, delay-500, and delay-1000 on the red, green, and blue boxes respectively.
4
Add custom fade-in animation in Tailwind config
Add a <script> block inside the <head> that uses tailwind.config to extend the animation with a fadeIn keyframe that changes opacity from 0 to 1 over 1 second with ease-in-out timing.
Tailwind
Hint
Use tailwind.config inside a <script> tag to extend the theme with keyframes and animation for fadeIn.
Practice
(1/5)
1. What does animation-delay do in Tailwind CSS animations?
easy
A. It changes the animation speed.
B. It waits before the animation starts.
C. It repeats the animation multiple times.
D. It stops the animation immediately.
Solution
Step 1: Understand animation-delay property
The animation-delay property sets a delay before the animation begins after the element loads or is triggered.
Step 2: Compare options with animation-delay behavior
Only waiting before the animation starts matches the animation-delay effect.
Final Answer:
It waits before the animation starts. -> Option B
Quick Check:
animation-delay = wait before start [OK]
Hint: Animation delay means wait time before animation starts [OK]
Common Mistakes:
Confusing delay with animation duration
Thinking delay repeats animation
Assuming delay stops animation
2. Which Tailwind class correctly sets an animation delay of 500 milliseconds?
easy
A. delay-500
B. animation-delay-500ms
C. animate-delay-500
D. delay-05
Solution
Step 1: Recall Tailwind delay class syntax
Tailwind uses delay-500 to set 500ms delay by default if configured.
Step 2: Check other options for correctness
Classes such as animation-delay-500ms and animate-delay-500 are not valid Tailwind classes. delay-05 uses wrong format.
Final Answer:
delay-500 -> Option A
Quick Check:
Tailwind delay class = delay-500 [OK]
Hint: Tailwind delay classes use delay-[time] format [OK]
Common Mistakes:
Adding 'animation-' prefix incorrectly
Using units like 'ms' in class name
Using decimal instead of full number
3. What will happen if you apply class="animate-bounce delay-1000" to a button?
medium
A. The button bounces immediately without delay.
B. The button never bounces because delay is too long.
The button will wait 1 second, then start bouncing normally.
Final Answer:
The button bounces after 1 second delay. -> Option C
Quick Check:
delay-1000 means 1s wait before animation [OK]
Hint: delay-1000 means wait 1 second before animation starts [OK]
Common Mistakes:
Thinking delay changes animation speed
Assuming delay cancels animation
Ignoring delay effect completely
4. You wrote <div class="animate-spin delay-2000ms"></div> but the delay does not work. What is the problem?
medium
A. Tailwind does not recognize 'delay-2000ms' because of 'ms' suffix.
B. The animate-spin class disables delay.
C. Delay must be set with inline style, not class.
D. The div needs an ID for delay to work.
Solution
Step 1: Check Tailwind delay class format
Tailwind delay classes use numbers only, no units like 'ms'. So 'delay-2000ms' is invalid.
Step 2: Verify other options
animate-spin does not disable delay; delay works with classes; IDs are not required.
Final Answer:
Tailwind does not recognize 'delay-2000ms' because of 'ms' suffix. -> Option A
Quick Check:
Tailwind delay classes do not include units [OK]
Hint: Tailwind delay classes never include units like 'ms' [OK]
Common Mistakes:
Adding 'ms' or 's' units in class names
Thinking animation disables delay
Using inline styles instead of classes
5. You want three boxes to fade in one after another with 0.5s delay between each. Which Tailwind classes correctly apply this effect?
hard
A. animate-fadeIn delay-05, animate-fadeIn delay-10, animate-fadeIn delay-15
B. animate-fadeIn delay-500, animate-fadeIn delay-1000, animate-fadeIn delay-1500
C. animate-fadeIn delay-1, animate-fadeIn delay-2, animate-fadeIn delay-3
D. animate-fadeIn delay-0, animate-fadeIn delay-500, animate-fadeIn delay-1000
Solution
Step 1: Understand delay increments for staggered animation
To fade in boxes one after another with 0.5s (500ms) delay between each, use delays of 0ms (first immediate), 500ms (second), 1000ms (third).
Step 2: Check Tailwind delay class naming
Tailwind standard classes include delay-0, delay-500, delay-1000 which match the required increments.
Step 3: Eliminate incorrect options
Combinations using delay-500, delay-1000, delay-1500 include non-standard delay-1500. Classes like delay-1, delay-2, delay-3 or delay-05, delay-10, delay-15 use invalid formats or values.
Final Answer:
animate-fadeIn delay-0, animate-fadeIn delay-500, animate-fadeIn delay-1000 -> Option D