Bird
Raised Fist0
Tailwindmarkup~5 mins

Spin animation (loading) in Tailwind

Choose your learning style10 modes available
Introduction

Spin animation shows that something is loading or working. It helps users know to wait.

When a page or data is loading and you want to show progress.
When a button triggers a process that takes time.
When fetching information from the internet.
When uploading or downloading files.
When waiting for a response from a server.
Syntax
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.

Examples
A small blue spinner with a transparent top border to create a spinning effect.
Tailwind
<div class="animate-spin h-6 w-6 border-4 border-blue-500 border-t-transparent rounded-full"></div>
An SVG spinner using Tailwind's animate-spin and color classes.
Tailwind
<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>
Sample Program

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.

Tailwind
<!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>
OutputSuccess
Important Notes

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.

Summary

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

(1/5)
1. What does the Tailwind CSS class animate-spin do to an element?
easy
A. Makes the element rotate continuously like a spinner
B. Changes the element's color to spinning colors
C. Stops any animation on the element
D. Makes the element fade in and out repeatedly

Solution

  1. Step 1: Understand the purpose of animate-spin

    The animate-spin class in Tailwind applies a continuous rotation animation to the element.
  2. Step 2: Compare with other animation effects

    Other options describe color changes or fading, which are not what animate-spin does.
  3. Final Answer:

    Makes the element rotate continuously like a spinner -> Option A
  4. Quick Check:

    animate-spin = continuous rotation [OK]
Hint: Remember spin means rotate continuously [OK]
Common Mistakes:
  • Confusing spin with color or fade animations
  • Thinking it stops animation
  • Assuming it changes element size
2. Which of the following is the correct Tailwind CSS syntax to create a spinning loader with a border?
easy
A. <div class='border-4 border-blue-500 spin-animation rounded-full'></div>
B. <div class='border-4 border-blue-500 spin animate rounded-full'></div>
C. <div class='border-4 border-blue-500 animate-spin-round rounded-full'></div>
D. <div class='border-4 border-blue-500 animate-spin rounded-full'></div>

Solution

  1. Step 1: Identify the correct animation class

    The official Tailwind class for spinning is animate-spin, so options A, B, and C use incorrect or non-existent classes.
  2. Step 2: Check the border and shape classes

    <div class='border-4 border-blue-500 animate-spin rounded-full'></div> correctly uses border-4 for thickness, border-blue-500 for color, and rounded-full for a circle shape.
  3. Final Answer:

    <div class='border-4 border-blue-500 animate-spin rounded-full'></div> -> Option D
  4. Quick Check:

    Correct Tailwind spin syntax = <div class='border-4 border-blue-500 animate-spin rounded-full'></div> [OK]
Hint: Use exact class animate-spin for spinning [OK]
Common Mistakes:
  • Using wrong animation class names
  • Missing rounded-full for circle shape
  • Confusing border color and thickness classes
3. What will be the visual result of this HTML snippet?
<div class='w-12 h-12 border-4 border-gray-300 border-t-blue-600 animate-spin rounded-full'></div>
medium
A. A static gray circle with a blue top border
B. A 48x48 pixel gray circle with a blue top border spinning continuously
C. A spinning square with gray and blue borders
D. A 12x12 pixel blue circle spinning continuously

Solution

  1. Step 1: Analyze size and shape classes

    w-12 and h-12 set width and height to 3rem (48px). rounded-full makes it a circle.
  2. Step 2: Understand border colors and animation

    border-4 sets border thickness. border-gray-300 colors all borders gray except border-t-blue-600 which colors top border blue. animate-spin makes it spin continuously.
  3. Final Answer:

    A 48x48 pixel gray circle with a blue top border spinning continuously -> Option B
  4. Quick Check:

    Size 12 + rounded + border colors + spin = 48x48 pixel gray circle with a blue top border spinning continuously [OK]
Hint: Remember w-12 = 3rem (48px), rounded-full = circle [OK]
Common Mistakes:
  • Confusing pixel size with rem units
  • Thinking it is a square without rounded-full
  • Ignoring the top border color override
4. You wrote this code for a spinner:
<div class='border-4 border-blue-500 rounded-full spin'></div>

Why does the spinner not rotate?
medium
A. The class spin is not a valid Tailwind animation class
B. Missing border-t-transparent to create spinner effect
C. The border-4 class is too thin to show animation
D. The rounded-full class disables animation

Solution

  1. Step 1: Check animation class correctness

    The class spin does not exist in Tailwind. The correct class for spinning is animate-spin.
  2. Step 2: Understand other classes' roles

    border-4 and rounded-full do not affect animation. Missing border-t-transparent affects spinner style but not rotation.
  3. Final Answer:

    The class spin is not a valid Tailwind animation class -> Option A
  4. Quick Check:

    Use animate-spin for rotation [OK]
Hint: Use exact class animate-spin for spinning [OK]
Common Mistakes:
  • Using spin instead of animate-spin
  • Thinking border thickness affects animation
  • Assuming rounded-full disables animation
5. You want to create an accessible spinning loader that announces "Loading" to screen readers but is visually hidden. Which Tailwind classes and attributes should you add?
hard
A. <div role='alert' aria-live='off'>Loading</div>
B. <div aria-hidden='true'>Loading...</div>
C. <div role='status' aria-live='polite'><span class='sr-only'>Loading...</span></div>
D. <div class='animate-spin' aria-label='Loading spinner'>Loading</div>

Solution

  1. Step 1: Use ARIA roles and live regions for announcements

    Setting role='status' and aria-live='polite' tells screen readers to announce changes politely.
  2. Step 2: Hide visible text but keep it accessible

    The sr-only class hides text visually but keeps it readable by screen readers, perfect for "Loading..." message.
  3. Final Answer:

    <div role='status' aria-live='polite'><span class='sr-only'>Loading...</span></div> -> Option C
  4. Quick Check:

    Use role='status' + sr-only for accessible loading [OK]
Hint: Use sr-only for hidden accessible text [OK]
Common Mistakes:
  • Using aria-hidden hides content from screen readers
  • Wrong aria-live values prevent announcements
  • Not using sr-only hides text visually and accessibly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard