Open In App

How to Build Tailwind CSS Progress Bar ?

Progress bars are essential for managing user expectations during operations like file uploads, downloads, or any process requiring waiting. Integrating progress bars into web applications, emphasizing the simplicity and efficiency that Tailwind CSS offers for designing and implementing these components.

Prerequisites

Approach to create Progress Bar using Tailwind CSS:

Example: Illustration of Designing a Animated Progress Bar in Tailwind CSS

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>The Animated Progress Bar</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>

<body class="bg-gray-100 flex justify-center
             items-center h-screen">
    <div class="w-1/3">
        <div class="text-center font-semibold mb-4">
              Progress: 
              <span id="progressText">0%</span>
          </div>
        <div class="relative h-8 bg-gray-200 rounded-full
                    overflow-hidden">
            <div id="progressBar" 
                 class="absolute top-0 left-0 h-full bg-green-500
                        transition-width duration-500">
              </div>
        </div>
    </div>
    <script>
        const progressFill = document.getElementById('progressBar');
        const progressText = document.getElementById('progressText');
        let progress = 0;
        const interval = setInterval(() => {
            progress += Math.random() * 10;
            if (progress > 100) {
                progress = 100;
                clearInterval(interval);
            }
            progressFill.style.width = 
                                  `${progress}%`;
            progressText.textContent = 
                                  `${Math.round(progress)}%`;
        }, 500);
    </script>
</body>

</html>

Output:

pgsgif

Output

Article Tags :