HTML progress Tag: How to Create Progress Bars with Examples

html progress tag

The <progress> tag in HTML shows task completion. It gives users visual feedback as the task runs.

Understand the <progress> Tag in HTML

The HTML <progress> tag shows how much of a task has finished. It acts like a progress bar. It works well for downloads or any step-by-step task.

Here is the basic tag:

<progress value="30" max="100"></progress>

Here is how it works:

  • value shows how much has finished.
  • max shows the full amount to complete.
  • The browser draws a progress bar based on these two values.

The browser divides value by max to get a percentage. That number controls the fill level.

  • If value="50" and max="100", the bar shows 50%.
  • If value="5" and max="10", the bar shows 50%.

Remove one of them, and the progress bar switches to an indeterminate state.

Use <progress> when the task:

  • Runs in steps
  • uploads or downloads content
  • Measures time or resource use

This tag only shows progress. It does not control or track the task.

Modern browsers support <progress>:

BrowserSupport
ChromeYes
FirefoxYes
SafariYes
EdgeYes
OperaYes

Old versions of Internet Explorer do not support it.

Attributes of the <progress> Tag in HTML

The value Attribute:

It shows how much of the task has finished.

<progress value="60" max="100"></progress>

This shows the bar at 60%. Users see that the task is more than halfway done.

The max Attribute:

Shows the total size of the task.

<progress value="25" max="50"></progress>

This shows 50%. Change max to raise or lower how fast the bar fills.

Default Behavior Without Attributes:

<progress></progress>

This runs in indeterminate mode. The bar shows an animation. The browser does not show any value.

Use this mode if the task length is unknown.

How to Style the <progress> Tag in HTML

Each browser gives its own look. You can style it like this:

progress {
  width: 200px;
  height: 20px;
}

This changes the size only. To style the color, use vendor selectors:

progress::-webkit-progress-bar {
  background-color: #eee;
}

progress::-webkit-progress-value {
  background-color: #4caf50;
}

Use similar rules for Firefox with ::-moz-progress-bar.

JavaScript Integration with the <progress> Element

You can use JavaScript to change the value.

<progress id="loader" value="0" max="100"></progress>

<script>
  const bar = document.getElementById('loader');
  bar.value = 30;
</script>

This updates the bar to 30%.

You can also track uploads or downloads.

<progress id="task" value="0" max="10"></progress>

<script>
  let val = 0;
  const bar = document.getElementById('task');

  const timer = setInterval(() => {
    if (val >= 10) {
      clearInterval(timer);
    } else {
      val++;
      bar.value = val;
    }
  }, 1000);
</script>

This simulates a task that takes 10 seconds. The bar fills one step per second.

The Differences Between <progress> and <meter>

The <progress> shows how much of a known task is done. While <meter> shows a numeric range like a score or health bar.

Here is a table that shows you the key differences:

Feature<progress><meter>
PurposeShow task progressShow value in a range
BehaviorCan animate (indeterminate)Always shows a set value
Use caseDownloads, uploadsScores or stats

Use <progress> for tasks like file uploads. Use <meter> for values like CPU usage or grades.

Examples

File Upload Progress Bar:

<progress value="70" max="100"></progress>

This shows a file upload that finished 70%. The bar shows the status clearly.

Indeterminate Task Progress:

<progress></progress>

This shows an unknown task length. The bar animates to show that the task runs, but does not show how much is left.

Auto-Fill with JavaScript:

<progress id="bar" value="0" max="5"></progress>

<script>
  const bar = document.getElementById("bar");
  let current = 0;

  const fill = setInterval(() => {
    current++;
    bar.value = current;

    if (current >= 5) {
      clearInterval(fill);
    }
  }, 500);
</script>

This shows a task that fills in steps. JavaScript updates the progress every half-second.

Styled Custom Bar:

<style>
  progress {
    width: 250px;
    height: 25px;
  }

  progress::-webkit-progress-bar {
    background: #ddd;
  }

  progress::-webkit-progress-value {
    background: #2196f3;
  }
</style>

<progress value="40" max="100"></progress>

This example customizes the look. It changes the color and size of the bar for better visibility.

Wrapping Up

In this article, you learned what the <progress> tag does and how it works in HTML and JavaScript. You also saw how to style it and where it fits in the HTML family.

Here is a quick recap:

  • Use <progress> to show task status.
  • Set value and max to control fill level.
  • Use it for downloads and loading bars. Also, you can use it for timers.
  • Style it with CSS for better looks.
  • Use JavaScript to update progress in real time.
  • Do not confuse it with <meter>.

FAQs

What is the purpose of the <progress> tag in HTML?

The <progress> tag in HTML represents the completion progress of a task such as downloading or uploading a file. It shows a visual bar that indicates how much of the task is complete.
<progress value="70" max="100"></progress>

How do you use the <progress> tag with JavaScript to show live updates?

You can manipulate the <progress> element using JavaScript to reflect real-time updates. Use the value attribute to update the progress dynamically.
<progress id="bar" max="100" value="0"></progress>
<script>
  let bar = document.getElementById("bar");
  let count = 0;
  let timer = setInterval(function() {
    if (count >= 100) {
      clearInterval(timer);
    } else {
      count++;
      bar.value = count;
    }
  }, 100);
</script>

What are the attributes of the <progress> tag?

The <progress> tag uses the following attributes:
  • value – current value of the task (optional)
  • max – total value when the task is complete (optional, defaults to 1)
<progress value="30" max="100"></progress>

What is the difference between <progress> and <meter> in HTML?

The <progress> tag shows task progress like file uploads, while <meter> shows a value within a known range, like disk usage or temperature.
<progress value="40" max="100"></progress>
<meter value="0.6"></meter>

Similar Reads

HTML Class Attribute: Use in CSS and JavaScript

The HTML class attribute helps group elements. It helps you update the page style without changing the structure of HTML.…

The em Tag in HTML: How to Emphasize Text in HTML

The HTML em tag shows stress or emphasis in text. It changes meaning for readers and screen readers. What is…

HTML br Tag: Line Breaks

The br tag adds a single line break in HTML. It is an empty tag that does not need a…

HTML dialog Tag: How to Create Dialog Boxes

The <dialog> tag is used to build modal popups in HTML. It shows alerts and messages without third-party scripts. Understand…

HTML Document Structure: How to Create DOCTYPE in HTML

The DOCTYPE ensures that your HTML is readable by browsers and ensures that pages follow modern standards. Understand the DOCTYPE…

HTML meter Tag: Measurements with Examples

Purpose and use cases: The HTML meter tag shows a scalar value within a known range. You can use it…

HTML source Tag: How to Embed Media with Examples

The source tag in HTML helps load different media formats and screen sizes. You can use it inside many other…

HTML Breadcrumb Navigation Guide for Beginners

The breadcrumb in HTML shows a path through a site and marks the place of a page inside it. It…

HTML a Tag: How to Add Links to Web Page with Examples

The HTML a tag allows you to create links that move users from one page or resource to another. Understand…

How to Open Link in New Tab with HTML Target

This article shows you how to open a link in a new tab. Read the code and follow the examples…

Previous Article

HTML Boolean Attributes with Examples

Next Article

HTML tabindex Attribute: How it Works with Examples

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.