Table of Content
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:
valueshows how much has finished.maxshows 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"andmax="100", the bar shows 50%. - If
value="5"andmax="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>:
| Browser | Support |
|---|---|
| Chrome | Yes |
| Firefox | Yes |
| Safari | Yes |
| Edge | Yes |
| Opera | Yes |
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> |
|---|---|---|
| Purpose | Show task progress | Show value in a range |
| Behavior | Can animate (indeterminate) | Always shows a set value |
| Use case | Downloads, uploads | Scores 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
valueandmaxto 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?
<progress value="70" max="100"></progress>
How do you use the <progress> tag with JavaScript to show live updates?
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?
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?
<progress value="40" max="100"></progress>
<meter value="0.6"></meter>
Similar Reads
You need images to show products or ideas on your site. The HTML img tag places those images on the…
The <main> tag in HTML marks the central content of a webpage. It tells browsers and assistive technologies where the…
The mark tag highlights text in HTML and shows that the text has relevance in the content. It adds a…
Use the HTML b tag to make text bold without giving it extra meaning. It adds visual weight only. Understand…
The HTML textarea tag gives users space to enter longer messages. This element helps build forms that accept feedback, comments,…
The HTML canvas tag draws shapes and images. It also helps you draw text with code. It gives control over…
The HTML time Tag marks time values in a document. Use it to show dates or times that machines and…
The header tag defines the top part of a page or a section in HTML. It usually holds a heading…
The HTML noscript tag tells the browser what to show when JavaScript does not run. This tag targets users who…
The heading elements define a content structure in HTML. Use <h1> to <h6> to show levels. <h1> means the main…