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.