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 data Tag: Machine-Readable Data

The data tag connects visible content with a machine-readable value in HTML. This helps browsers and tools understand and process…

HTML wbr Tag: Word Break Opportunities

The <wbr> tag in HTML helps the browser decide where it can break a word. It does not force a…

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…

HTML bdi Tag: Control Text Direction in HTML

The HTML bdi tag marks text that has an unknown or mixed direction. It makes sure that this part does…

Component-driven HTML Guide with Examples

This guide shows how to build HTML with separate parts as components and how each part helps in reuse and…

How to Create HTML Nested Lists with Examples

In this article, you will learn how the browsers read nested lists in HTML and how to use them with…

HTML List Tag: Understand the ul, ol, and dl Lists

HTML has three main list tags: <ul>, <ol>, and <dl>. Each one shows a different kind of group. In this…

HTML base Tag: How to Set a Base URL for Links and Resources

Use the <base> tag in HTML to set a single base URL or target for all relative links and resources…

HTML tabindex Attribute: How it Works with Examples

The HTML tabindex Attribute lets you change the tab order on a web page. It helps control keyboard access. What…

HTML Element: Everything You Need To Know with Examples

An HTML element builds every part of a web page. It holds the text or block you want the browser…

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.