Use <progress> to show how much of a task has been completed, such as an upload or data-processing job. Use <meter> for a numeric measurement within a known range, such as disk usage, a score, or battery level.
The two elements may look similar in a browser, but they represent different information and should not be used interchangeably.
<label for="fileProgress">File upload progress:</label>
<progress id="fileProgress" value="25" max="100">25%</progress>
Here, 25 out of 100 means the task is 25% complete. The text between the tags is useful fallback text, but the element should still have an accessible label.
The value attribute gives the amount of work completed. It must be between 0 and max. If max is omitted, the range is from 0 to 1.
The max attribute sets the total amount of work and must be greater than zero. Its default value is 1.
value attribute is missing. The presence or absence of max does not determine this.<progress value="50" max="100">50%</progress>
Use a determinate progress bar when the application knows how much work has been completed.
<label for="loadingProgress">Loading data:</label>
<progress id="loadingProgress">Loading</progress>
Omit value when a task is running but the application cannot yet calculate its percentage of completion.
<progress value="0.5">50%</progress>
Because max is omitted, the default maximum is 1, so 0.5 represents 50%.
Progress elements are commonly updated by JavaScript when an application receives new status information.
const progress = document.getElementById("demoProgress");
const button = document.getElementById("increaseProgress");
button.addEventListener("click", () => {
progress.value = Math.min(progress.value + 20, progress.max);
progress.textContent = `${progress.value}%`;
});
For a complete JavaScript example, see managing a progress bar with JavaScript. Plus2net also has a PHP and Ajax progress example.
The <meter> element represents a scalar value within a known range. It is appropriate for measurements such as storage usage, ratings, scores, or battery level. It should not be used to represent the completion of a task.
<label for="diskUsage">Disk usage:</label>
<meter id="diskUsage" min="0" max="100" value="70">70%</meter>
0.1.<label for="batteryLevel">Battery level:</label>
<meter id="batteryLevel" min="0" max="100"
low="20" high="80" optimum="90" value="50">50%</meter>
The browser can use low, high, and optimum to indicate whether the current measurement is in a preferred or less-preferred part of the range.
| Element | Use it for | Typical example |
|---|---|---|
<progress> | Completion of an ongoing task | Upload is 60% complete |
<meter> | A measurement within a known range | Disk is 70% full |
<label> associated with the element is a good default.value rather than replacing it with a purely visual CSS bar.value attribute rather than inserting an invented percentage.<meter> for task completion.<progress> for a static measurement such as temperature or disk capacity.min attribute to <progress>; its minimum is always zero.max without value makes the bar determinate. A missing value means indeterminate progress.The default max is 1. For example, value="0.5" represents 50% when max is omitted.
Leave out the value attribute. Use this when work is happening but the application cannot calculate completion yet.
No. The minimum for <progress> is always zero.
<progress> represents task completion. <meter> represents a measurement within a known range.
Yes. JavaScript can update the element's value property as new progress information becomes available.
Manage a progress bar with JavaScript
Update progress using PHP and Ajax
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| Md Shahab Alam | 06-06-2016 |
| Thanks Sir,Your Tutorial is very usefull | |