Ping animation helps show new notifications or alerts in a friendly, eye-catching way.
Ping animation (notifications) in Tailwind
<div class="relative"> <span class="absolute inline-flex h-3 w-3 rounded-full bg-red-400 opacity-75 animate-ping"></span> <span class="relative inline-flex rounded-full h-3 w-3 bg-red-500"></span> </div>
The animate-ping class creates the expanding circle effect.
Use two <span> elements: one for the ping animation and one for the solid dot.
<div class="relative"> <span class="absolute inline-flex h-4 w-4 rounded-full bg-green-400 opacity-75 animate-ping"></span> <span class="relative inline-flex rounded-full h-4 w-4 bg-green-500"></span> </div>
<div class="relative"> <span class="absolute inline-flex h-2 w-2 rounded-full bg-blue-400 opacity-75 animate-ping"></span> <span class="relative inline-flex rounded-full h-2 w-2 bg-blue-500"></span> </div>
<button class="relative p-2"> Notifications <span class="absolute top-0 right-0 inline-flex h-3 w-3 rounded-full bg-red-400 opacity-75 animate-ping"></span> <span class="absolute top-0 right-0 inline-flex rounded-full h-3 w-3 bg-red-500"></span> </button>
This example shows a button labeled "Notifications" with a red ping animation on the top-right corner. The ping circle expands and fades out repeatedly, drawing attention to new alerts.
Accessibility is added with aria-label and role="status" so screen readers announce the new notification.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Ping Animation Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="flex items-center justify-center min-h-screen bg-gray-100"> <button class="relative p-3 bg-white rounded-md shadow-md font-semibold text-gray-800"> Notifications <span class="absolute top-2 right-2 inline-flex h-4 w-4 rounded-full bg-red-400 opacity-75 animate-ping" aria-hidden="true"></span> <span class="absolute top-2 right-2 inline-flex rounded-full h-4 w-4 bg-red-500" aria-label="New notifications" role="status"></span> </button> </body> </html>
Use relative on the container to position the ping elements absolutely inside it.
Keep the solid dot on top so the ping circle appears behind it.
Use aria-label and role="status" for accessibility to announce notifications.
Ping animation uses two overlapping circles: one solid and one expanding with fading.
Tailwind's animate-ping class creates the expanding effect easily.
Position the ping inside a relative container for correct placement.