Spin animation shows that something is loading or working. It helps users know to wait.
Spin animation (loading) in Tailwind
<div class="animate-spin">...</div>animate-spin is a Tailwind CSS class that makes an element spin continuously.
You can add size and color classes to style the spinner.
<div class="animate-spin h-6 w-6 border-4 border-blue-500 border-t-transparent rounded-full"></div><svg class="animate-spin h-8 w-8 text-gray-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle> <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"></path> </svg>
This code shows a blue circular spinner in the center of the page. The spinner uses Tailwind's animate-spin class to rotate continuously. The border-t-transparent creates the spinning effect by making the top border invisible.
It also uses role="status" and aria-label="Loading" for accessibility, so screen readers announce the loading state.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Spin Animation Loading</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="flex items-center justify-center min-h-screen bg-gray-100"> <div class="animate-spin h-12 w-12 border-4 border-blue-600 border-t-transparent rounded-full" role="status" aria-label="Loading"> </div> </body> </html>
Use role="status" and aria-label for accessibility so screen readers know the spinner means loading.
You can change spinner size by adjusting h- and w- classes.
Use contrasting colors for good visibility and accessibility.
animate-spin makes elements spin continuously in Tailwind CSS.
Use border styles and colors to create a spinner shape.
Add accessibility attributes so all users understand the loading state.
Practice
animate-spin do to an element?Solution
Step 1: Understand the purpose of
Theanimate-spinanimate-spinclass in Tailwind applies a continuous rotation animation to the element.Step 2: Compare with other animation effects
Other options describe color changes or fading, which are not whatanimate-spindoes.Final Answer:
Makes the element rotate continuously like a spinner -> Option AQuick Check:
animate-spin= continuous rotation [OK]
- Confusing spin with color or fade animations
- Thinking it stops animation
- Assuming it changes element size
Solution
Step 1: Identify the correct animation class
The official Tailwind class for spinning isanimate-spin, so options A, B, and C use incorrect or non-existent classes.Step 2: Check the border and shape classes
<div class='border-4 border-blue-500 animate-spin rounded-full'></div>correctly usesborder-4for thickness,border-blue-500for color, androunded-fullfor a circle shape.Final Answer:
<div class='border-4 border-blue-500 animate-spin rounded-full'></div> -> Option DQuick Check:
Correct Tailwind spin syntax =<div class='border-4 border-blue-500 animate-spin rounded-full'></div>[OK]
animate-spin for spinning [OK]- Using wrong animation class names
- Missing
rounded-fullfor circle shape - Confusing border color and thickness classes
<div class='w-12 h-12 border-4 border-gray-300 border-t-blue-600 animate-spin rounded-full'></div>
Solution
Step 1: Analyze size and shape classes
w-12andh-12set width and height to 3rem (48px).rounded-fullmakes it a circle.Step 2: Understand border colors and animation
border-4sets border thickness.border-gray-300colors all borders gray exceptborder-t-blue-600which colors top border blue.animate-spinmakes it spin continuously.Final Answer:
A 48x48 pixel gray circle with a blue top border spinning continuously -> Option BQuick Check:
Size 12 + rounded + border colors + spin = 48x48 pixel gray circle with a blue top border spinning continuously [OK]
- Confusing pixel size with rem units
- Thinking it is a square without rounded-full
- Ignoring the top border color override
<div class='border-4 border-blue-500 rounded-full spin'></div>
Why does the spinner not rotate?
Solution
Step 1: Check animation class correctness
The classspindoes not exist in Tailwind. The correct class for spinning isanimate-spin.Step 2: Understand other classes' roles
border-4androunded-fulldo not affect animation. Missingborder-t-transparentaffects spinner style but not rotation.Final Answer:
The classspinis not a valid Tailwind animation class -> Option AQuick Check:
Useanimate-spinfor rotation [OK]
animate-spin for spinning [OK]- Using
spininstead ofanimate-spin - Thinking border thickness affects animation
- Assuming rounded-full disables animation
Solution
Step 1: Use ARIA roles and live regions for announcements
Settingrole='status'andaria-live='polite'tells screen readers to announce changes politely.Step 2: Hide visible text but keep it accessible
Thesr-onlyclass hides text visually but keeps it readable by screen readers, perfect for "Loading..." message.Final Answer:
<div role='status' aria-live='polite'><span class='sr-only'>Loading...</span></div> -> Option CQuick Check:
Userole='status'+sr-onlyfor accessible loading [OK]
sr-only for hidden accessible text [OK]- Using aria-hidden hides content from screen readers
- Wrong aria-live values prevent announcements
- Not using
sr-onlyhides text visually and accessibly
Ready to prove it?
Pass the test and this pattern moves unknown
