Open In App

How to create a progress bar using bootstrap ?

Last Updated : 22 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Bootstrap is an open-source framework used to design responsive websites which are easy and efficient to use. It has ready-made templates which can be used to design web pages in a limited time.

What is a progress bar?

A progress bar is used whenever there is a need for a visual interface to show progress in a particular task. Let's say, "How much percentage of files has been downloaded or how many percent of students passed in an exam".

For this purpose, Bootstrap has a progress bar component that can be used on web pages. All the versions of Bootstrap support the progress bar component.

  
 How to add a progress bar using Bootstrap? 

  1. Visit the official page of Bootstrap here. On the right side, the bootstrap version can be selected suitable as per requirements. But its recommended to use latest version as it has new features embedded inside it.
  2. On the left side panel under Components section, Progress tab can be seen. Under progress tab the progress bar components can be seen.
  3. Now the template present can directly be used. This can be done by putting the template under body section of html page.


 Example 1: The starter template from documentation tab of bootstrap can be used. 

HTML
<!doctype html>
<html lang="en">

<head>
    <!-- Bootstrap CSS and JS -->
    <link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
          rel="stylesheet"
          crossorigin="anonymous">

    <script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
            crossorigin="anonymous">
      </script>
</head>

<body>
    <div class="progress">
        <div class="progress-bar" role="progressbar"
            aria-valuenow="0" aria-valuemin="0" 
            aria-valuemax="100">
        </div>
    </div>
    <div class="progress">
        <div class="progress-bar" role="progressbar" 
            style="width: 25%" aria-valuenow="25" 
            aria-valuemin="0"
            aria-valuemax="100">
        </div>
    </div>
    <div class="progress">
        <div class="progress-bar" role="progressbar" 
            style="width: 50%" aria-valuenow="50"
            aria-valuemin="0"
            aria-valuemax="100">
        </div>
    </div>
    <div class="progress">
        <div class="progress-bar" role="progressbar" 
            style="width: 75%" aria-valuenow="75" 
            aria-valuemin="0"
            aria-valuemax="100">
        </div>
    </div>
    <div class="progress">
        <div class="progress-bar" role="progressbar" 
            style="width: 100%" aria-valuenow="100" 
            aria-valuemin="0"
            aria-valuemax="100">
        </div>
    </div>
</body>

</html>

Output: The following progress bar can be seen on the webpage.

Example 2: We can display the percentage of the progress bar by writing it in between the div of the progress bar.

Syntax:

<div class="progress">
<div class="progress-bar"
role="progressbar"
style="width: 25%;"
aria-valuenow="25"
aria-valuemin="0"
aria-valuemax="100">25%
</div>
</div>

Code:

HTML
<!doctype html>
<html lang="en">

<head>
    <!-- Bootstrap CSS and JS -->
    <link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" 
          rel="stylesheet"
        crossorigin="anonymous">

    <script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" 
            crossorigin="anonymous">
    </script>
</head>

<body>
    <h2>Bootstrap Progress Bar</h2>
    <div class="progress">
        <div class="progress-bar" 
             role="progressbar" 
             style="width: 25%;" 
             aria-valuenow="25" 
             aria-valuemin="0" 
             aria-valuemax="100">
          25%
      </div>
      </div>
</body>

</html>

Output: 

NOTE: The value for the progress can be changed in the code as per the requirement.

Appearance

We can change the appearance of the progress bar using the bootstrap background utilities classes like "bg-info" , "bg-success", "bg-warning" and many more.

Syntax:

<div class="progress">
<div class="progress-bar bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>

Here is a code example in which we have made progress bars of different colors using different background utility classes.

Code:

HTML
<!doctype html>
<html lang="en">

<head>
    <!-- Bootstrap CSS and JS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
        crossorigin="anonymous">

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous">
    </script>
</head>

<body>
    <h2>Bootstrap Progress Bar</h2>
    <div class="progress" style="margin: 5px;">
        <div class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="20" aria-valuemin="0"
            aria-valuemax="100">
        </div>
    </div>
   
    <div class="progress" style="margin: 5px;">
        <div class="progress-bar bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0"
            aria-valuemax="100"></div>
    </div>
    <div class="progress" style="margin: 5px;">
        <div class="progress-bar bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0"
            aria-valuemax="100"></div>
    </div>
    <div class="progress" style="margin: 5px;">
        <div class="progress-bar bg-warning" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0"
            aria-valuemax="100"></div>
    </div>
    <div class="progress" style="margin: 5px;">
        <div class="progress-bar bg-danger" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0"
            aria-valuemax="100"></div>
    </div>

</body>

</html>

Output:

Bootstrap Progress Bar in different appearances

Stripped Progress Bar

We can make stripped progress bar using the class "progress-bar-stripped" along with the "progress-bar" class in the component.

Syntax:

<div class="progress">
<div class="progress-bar progress-bar-stripped"
role="progressbar"
style="width: 25%"
aria-valuenow="25"
aria-valuemin="0"
aria-valuemax="100">
</div>
</div>

Code:

HTML
<!doctype html>
<html lang="en">

<head>
    <!-- Bootstrap CSS and JS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
        crossorigin="anonymous">

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous">
    </script>
</head>

<body>
    <h2>Bootstrap Stripped Progress Bar</h2>

    <div class="progress" style="margin: 5px;">
        <div class="progress-bar progress-bar-stripped" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
      </div>
      <div class="progress" style="margin: 5px;">
        <div class="progress-bar progress-bar-stripped bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
      </div>
      <div class="progress" style="margin: 5px;">
        <div class="progress-bar progress-bar-stripped bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
      </div>
      <div class="progress" style="margin: 5px;">
        <div class="progress-bar progress-bar-stripped bg-warning" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
      </div>
      <div class="progress" style="margin: 5px;">
        <div class="progress-bar progress-bar-stripped bg-danger" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
      </div>

</body>

</html>

Output:

Bootstrap Stripped Progress Bar

Animated Progress Bar

We can make animated progress bar using the class "progress-bar-animated" along with the "progress-bar" class in the component.

Syntax:

<div class="progress">
<div class="progress-bar progress-bar-stripped progress-bar-animated"
role="progressbar"
aria-valuenow="75"
aria-valuemin="0"
aria-valuemax="100" style="width: 75%">
</div>
</div>

Code:

HTML
<!doctype html>
<html lang="en">

<head>
    <!-- Bootstrap CSS and JS -->
    <link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" 
          rel="stylesheet"
        crossorigin="anonymous">

    <script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" 
            crossorigin="anonymous">
    </script>
</head>

<body>
    <h2>Bootstrap Animated Progress Bar</h2>
    <div class="progress">
        <div class="progress-bar progress-bar-stripped progress-bar-animated" 
             role="progressbar" aria-valuenow="75" 
             aria-valuemin="0" aria-valuemax="100" 
             style="width: 75%">
      </div>
      </div>

</body>

</html>

Output:

Supported Browsers:

  • Google Chrome
  • Opera
  • Safari
  • Mozilla Firefox
  • Brave Browser

Next Article

Similar Reads