HTML Progress and Meter
Two Kinds of Bars
HTML has two elements that show a value as a bar:
<progress>shows how much of a task is done, like a download progress<meter>shows a measurement within a known range, like disk usage or a test score
The browser draws both bars for you. you do not need any images or CSS.
The <progress> Element
The <progress> element shows how far a task has come.
The value attribute defines how much of the
task is done, and max is the total:
Example
<label for="file">Downloading file:</label>
<progress id="file" value="70" max="100">70%</progress>
Try it Yourself »
In the example above, the bar is 70% full.
The text between the tags (70%) is shown only by very old browsers that do not support the <progress> element.
Tip: Always use a <label>, so screen reader users know what the bar is about.
A Progress Bar Without a Value
Sometimes you do not know how long a task will take.
Leave out the value attribute, and the browser shows a moving bar that means "working on it":
Example
<label for="loading">Loading:</label>
<progress id="loading" max="100"></progress>
Try it Yourself »
Update a Progress Bar
A progress bar is most useful when it is live, and changes.
A JavaScript can change the value while the task goes on:
Example
<progress id="steps" value="0" max="5">0 of 5</progress>
<button onclick="nextStep()">Next step</button>
<p id="status">0 of 5 steps done.</p>
<script>
function nextStep() {
var bar = document.getElementById("steps");
if (bar.value < bar.max) {
bar.value = bar.value + 1;
}
document.getElementById("status").innerHTML = bar.value + " of 5 steps done.";
}
</script>
Try it Yourself »
In the example above, each click fills one more part of the bar. After five clicks, the page shows:
5 of 5 steps done.
The <meter> Element
The <meter> element shows a value within a known range,
like disk usage or a test score.
Use min and max to set the range.
If you leave them out, the range is from 0 to 1:
Example
<label for="disk">Disk usage:</label>
<meter id="disk" value="0.6">60%</meter>
<label for="score">Test score:</label>
<meter id="score" value="7" min="0" max="10">7 out of 10</meter>
Try it Yourself »
High, Low, and Optimum Values
The <meter> element can also be used to show
if a value is good or bad.
The low and high attributes split the range into three parts.
The optimum attribute tells the browser which
value is the best:
Example
<meter value="90" min="0" max="100" low="20" high="80" optimum="100">90%</meter>
<meter value="50" min="0" max="100" low="20" high="80" optimum="100">50%</meter>
<meter value="10" min="0" max="100" low="20" high="80" optimum="100">10%</meter>
Try it Yourself »
This is a battery level, where a full battery is best.
- 90% is above
high, near the best value, so the bar is green - 50% is between
lowandhigh, so the bar is yellow - 10% is below
low, far from the best value, so the bar is red
Note: The colors and the look of the bars can be different in each browser.
Always show the number as text too, so the value is clear without the color.
Use <progress> or <meter>?
| <progress> | <meter> | |
|---|---|---|
| Shows | How much of a task is done | A measurement within a range |
| Changes over time | Yes, it moves toward the end | Not usually |
| Can show good or bad values | No | Yes, with low, high, and optimum |
| Good for | Downloads, uploads, steps in a form | Disk usage, battery level, test scores |
A simple rule: If something will be finished at some point, use <progress>. If you are measuring something, use <meter>.
Summary
<progress>shows how much of a task is done, withvalueandmax<meter>shows a value within a range, withminandmaxlow,high, andoptimummark values as good, okay, or bad- Always add a
<label>, and show the number as text
HTML Tag Reference
| Tag | Description |
|---|---|
| <progress> | Shows how much of a task is done |
| <meter> | Shows a measurement within a known range |
For a complete list of all available HTML tags, visit our HTML Tag Reference.