How to use utility classes In CSS

To create a loading button, you can use the Tailwind CSS utility classes as described above. In this example, we use the “animate-spin” utility class to create an infinite spinner to depict the loading animation.

Example: Implemenatation to create animated loading button using utility classes.

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
    <title>
        To create Animated Loading Button
    </title>
 
    <!-- font awesome cdn -->
    <link rel="stylesheet" href=
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
          integrity=
"sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
          crossorigin="anonymous"
          referrerpolicy="no-referrer" />
    <script src="https://cdn.tailwindcss.com"></script>
</head>
 
<body class="flex flex-col justify-center items-center py-10">
    <h1 class="text-green-500 text-2xl font-bold">w3wiki</h1>
    <h4 class="text-lg font-bold">
        Creating Animated Loading
          Button using Tailwind CSS
    </h4>
    <button disabled
            class="flex items-center justify-center gap-2
                   px-5 py-2 mt-2 rounded bg-green-500 text-white
                   disabled:bg-green-500/80 disabled:cursor-not-allowed">
            Loading
          <i class="animate-spin fa-solid fa-circle-notch"></i>
    </button>
</body>
 
</html>


Output:

How to Create Animated Loading Button using Tailwind CSS ?

To create an animated loading button using Tailwind CSS, first, define the button structure with the loading animation. We can utilize Tailwind CSS classes to style the button and animation, such as ‘bg-green-500’ for background color and animate-spin for rotation.

Similar Reads

Syntax:

... content
...

Using utility classes

To create a loading button, you can use the Tailwind CSS utility classes as described above. In this example, we use the “animate-spin” utility class to create an infinite spinner to depict the loading animation....

Using custom animation

...