Introduction
Progress bar is used to view someone's progress report. We can get a report of how much someone has progressed with his/her work. We can use it during page loading to calculate the percentage of the page loaded. We can use it to get someone's work status report.
Static progress bar demo
For creating a default static progress bar, we need the following elements.
- <div class="progress">
- <div class="progress-bar" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
- <span class="sr-only">40% Complete</span>
- </div>
- </div>
aria-valuenow- This is known as curent progress bar value.
aria-valuemin- This is known as initial value of the progress bar value.
aria-valuemax- This is known as maximum value of the progress bar value.
Types
The following types of progress bars are available.
- Basic progress bar - This is known as a default progress bar in bootstrap. It is the same as the above demo.
- Progress bar with a label - We will remove the sr-only class from the progress bar for viewing the progress value.
- Colored progress bar - For a colorful progress bar, we need it. There are some by-default classes for colors, like success, info, danger etc. If we want to add customized color, then we will add that color through the style tag or we will create a class for color.
- Striped progress bar - We just need to add '.progress-bar-striped' class to get a striped design progress bar.
- Animated progress bar - We just need to add 'active' class to get an animated design progress bar.
- Stacked progress bar - It shows multiple bars into the same.
Example
Here, we will take an example of dynamic animated progress bar.
- <html lang="en">
- <head>
- <title>Bootstrap Example</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- var progressBarVal=80;
- var html="<div class='progress-bar progress-bar-striped active' role='progressbar' aria-valuenow="+progressBarVal+" aria-valuemin='0' aria-valuemax='100' style='width:"+progressBarVal+"%'>"+progressBarVal+"%</div>";
- $(".progress").append(html);
- });
- </script>
- </head>
- <body>
-
- <div class="container">
- <h1>The below progress bar is showing that the progress value is 80% </h1>
- <div class="progress">
-
- </div>
- </div>
-
- </body>
- </html>
The above dynamic progress bar is showing that the value of the progress bar is 80%.
Summary
In this blog and code example, I discussed the type of bootstrap progress bar and how we can use it dynamically.