Follow @endyourif rss Facebook LinkedIn

Displaying a Progress Bar with HTML Displaying a Progress Bar with HTML

Published on Mar 11, 2019

HTML5 now contains a markup tag progress. This displays a basic progress bar based on two attributes that you must specify: the current value and the max value. Using some basic Javascript, you can increment the progress bar so the user knows something is happening and will be done soon.

Creating the progress bar

The following code will create a progress bar that will go from 0 to 100 increments by 5% each second. Here is the code to display and increment the progress bar:

<!DOCTYPE html>
<title>Progress bar</title>


<script src=""></script>
<progress id="myProgress" value="0" max="100"></progress>

var timer;
var progress;
var max;
$(document).ready(function() {
progress = $("#myProgress");
max = progress.attr("max");
timer = setInterval("updateBar()", 1000);

function updateBar() {
var current = progress.attr("value");
current += 5;
progress.attr("value", current);

if (current >= max) {

The Javascript behind the progress bar

Using some basic Javascript, I set an interval timer for every second to call the updateBar function. This function uses some basic jQuery to retrieve the current value and increment it by 5. Using the same basic jQuery it changes the value as well. Finally, if the progress bar has reached 100%, the timer is cleared.

The progress tag is a great and simple addition to HTML5. As more browsers support its features, it will become a pivotal role in game making because you will want a fast loading web page and then asynchronously load your actual game mechanics. What better way to load these and inform the user of their progress than a progress bar!

Tags: html | JavaScript | jQuery Tutorial

My Books
ASP.NET MVC 5 With Bootstrap and Knockout.js
Knockout.js Building Dynamic Client-Side Applications
20 Recipes for Programming MVC 3
20 Recipes for Programming PhoneGap
Rapid Application Development with CakePHP