HTML - HTML <meter> and <progress> Elements
The HTML <meter> and <progress> elements are semantic HTML elements used to visually represent numerical values. Although they may look similar in a browser, they serve different purposes. The <progress> element represents the completion status of a task, while the <meter> element represents a measurement within a known range.
Understanding the difference between these two elements is important when developing accessible and semantically meaningful web pages.
1. The <progress> Element
The <progress> element represents the completion progress of a specific task.
For example, it can be used to show:
-
File upload progress
-
File download progress
-
Installation progress
-
Form completion
-
Course completion
-
Data processing status
-
Software installation status
The basic syntax is:
<progress value="60" max="100"></progress>
Here:
-
value="60"represents the current progress. -
max="100"represents the total amount of work. -
The browser displays a progress bar indicating that 60% of the task has been completed.
Example
<label for="download">Download Progress:</label>
<progress id="download" value="70" max="100"></progress>
The browser interprets this as a task that is 70 percent complete.
2. Determinate Progress
When both the value and max attributes are specified, the progress bar has a known completion value. This is called determinate progress.
For example:
<progress value="25" max="100"></progress>
This indicates that 25 out of 100 units have been completed.
The percentage can be calculated using:
Percentage = (value / max) × 100
Therefore:
(25 / 100) × 100 = 25%
Another example is:
<progress value="3" max="10"></progress>
This represents 3 completed units out of 10, or 30 percent.
3. Indeterminate Progress
A <progress> element can also represent a task whose exact completion percentage is not currently known.
For example:
<progress></progress>
When the value attribute is omitted, browsers generally display the element as an indeterminate progress indicator.
This can be useful when a website is processing something but cannot determine exactly how much work remains.
For example, a server might be processing a large request, but the browser may not know whether the operation is 20%, 50%, or 90% complete.
4. The max Attribute
The max attribute specifies the total amount of work.
For example:
<progress value="40" max="200"></progress>
Here, 40 units have been completed out of a total of 200.
The completion percentage is:
(40 / 200) × 100 = 20%
The max attribute is optional. If it is omitted, the default maximum value for <progress> is 1.
For example:
<progress value="0.5"></progress>
represents 50 percent completion.
5. The <meter> Element
The <meter> element represents a scalar measurement within a known range.
Unlike <progress>, it does not represent the completion of a task.
Typical examples include:
-
Disk usage
-
Battery level
-
Exam score
-
Temperature
-
Storage utilization
-
Network signal strength
-
Product rating
-
Server capacity
The basic syntax is:
<meter value="70" min="0" max="100"></meter>
This represents a measurement of 70 on a scale from 0 to 100.
6. Understanding the Difference Between <meter> and <progress>
The easiest way to understand the difference is to consider the question each element answers.
<progress> answers:
"How much of this task has been completed?"
<meter> answers:
"Where does this measurement fall within a particular range?"
For example, suppose a user is downloading a 100 MB file and 60 MB has been downloaded:
<progress value="60" max="100"></progress>
This is appropriate because the download is a task that is 60 percent complete.
Now consider a computer with 60 percent of its storage being used:
<meter value="60" min="0" max="100"></meter>
This is appropriate because storage usage is a measurement, not a task being completed.
7. <meter> Attributes
The <meter> element supports several important attributes.
value
The value attribute specifies the current measurement.
<meter value="75"></meter>
min
The min attribute specifies the lower boundary.
<meter min="0" value="75" max="100"></meter>
max
The max attribute specifies the upper boundary.
<meter min="0" value="75" max="100"></meter>
low
The low attribute specifies a threshold that represents a low value.
<meter min="0" low="30" high="70" max="100" value="20"></meter>
Here, 20 is below the low threshold of 30.
high
The high attribute specifies a threshold considered high.
<meter min="0" low="30" high="70" max="100" value="80"></meter>
Here, the value of 80 is above the high threshold of 70.
optimum
The optimum attribute indicates the preferred or ideal value.
<meter min="0" low="30" high="70" max="100" optimum="50" value="50"></meter>
This indicates that 50 is the preferred value.
8. Example of <meter> for Storage Usage
Suppose a computer has used 750 GB of a 1000 GB drive.
<label for="storage">Storage Used:</label>
<meter
id="storage"
min="0"
max="1000"
value="750">
</meter>
The measurement is:
750 GB out of 1000 GB
The meter represents the current storage usage rather than the completion of a task.
9. Example of <meter> With Thresholds
You can use low, high, and optimum to provide additional semantic information.
<label for="temperature">Temperature:</label>
<meter
id="temperature"
min="0"
max="100"
low="30"
high="70"
optimum="50"
value="80">
</meter>
In this example:
-
Minimum value is 0.
-
Maximum value is 100.
-
Values below 30 are considered low.
-
Values above 70 are considered high.
-
50 is considered the optimum value.
-
The current measurement is 80.
The browser can use this information when rendering the meter.
10. Comparing Both Elements
Consider an online learning platform.
Suppose a student has completed 8 out of 10 lessons.
This is a task, so <progress> should be used:
<label for="course-progress">Course Completion:</label>
<progress
id="course-progress"
value="8"
max="10">
</progress>
Now suppose the student's test score is 80 out of 100.
This is a measurement, so <meter> is appropriate:
<label for="score">Test Score:</label>
<meter
id="score"
min="0"
max="100"
value="80">
</meter>
The two elements may appear visually similar, but their semantic meanings are different.
11. Using <progress> With JavaScript
The value of a progress bar can be dynamically changed using JavaScript.
HTML:
<progress id="uploadProgress" value="0" max="100"></progress>
JavaScript:
const progress = document.getElementById("uploadProgress");
let value = 0;
const interval = setInterval(() => {
value += 10;
progress.value = value;
if (value >= 100) {
clearInterval(interval);
}
}, 500);
The progress bar gradually increases from 0 to 100.
This technique can be used for simulated processing, file uploads, downloads, or other operations where the application knows the completion percentage.
12. Dynamically Updating a <meter>
A meter can also be updated dynamically.
<label for="battery">Battery:</label>
<meter
id="battery"
min="0"
max="100"
value="80">
</meter>
<script>
const battery = document.getElementById("battery");
battery.value = 65;
</script>
The displayed measurement changes from 80 to 65.
This can be useful when displaying real-time information such as battery level, storage consumption, or system capacity.
13. Accessibility Considerations
Semantic HTML elements can provide useful information to assistive technologies, but they should still be associated with understandable labels.
For example:
<label for="courseProgress">Course Completion:</label>
<progress
id="courseProgress"
value="75"
max="100">
</progress>
The label tells the user what the progress bar represents.
Similarly:
<label for="storageUsage">Storage Used:</label>
<meter
id="storageUsage"
min="0"
max="100"
value="75">
</meter>
The label makes the purpose of the measurement clear.
Avoid relying solely on color or visual appearance to communicate important information.
14. Common Mistake: Using <meter> for Task Progress
One common mistake is using <meter> for a task that is being completed.
For example:
<meter value="70" min="0" max="100"></meter>
If this represents a file download that is 70 percent complete, <progress> would be semantically more appropriate:
<progress value="70" max="100"></progress>
The distinction is based on meaning, not appearance.
15. Common Mistake: Using <progress> for Measurements
The reverse mistake is also possible.
Suppose a website wants to show that a student's exam score is 85 out of 100.
Using:
<progress value="85" max="100"></progress>
suggests that the student is 85 percent through a task.
A better choice for a score or measurement is:
<meter min="0" max="100" value="85"></meter>
This communicates that 85 is a measurement on a scale from 0 to 100.
16. Practical Examples
File Upload
Use <progress>:
<label for="fileUpload">File Upload:</label>
<progress id="fileUpload" value="45" max="100"></progress>
Course Completion
Use <progress>:
<label for="course">Course Completion:</label>
<progress id="course" value="7" max="10"></progress>
Disk Usage
Use <meter>:
<label for="disk">Disk Usage:</label>
<meter id="disk" min="0" max="100" value="82"></meter>
Exam Score
Use <meter>:
<label for="examScore">Exam Score:</label>
<meter id="examScore" min="0" max="100" value="92"></meter>
Battery Level
Use <meter>:
<label for="batteryLevel">Battery Level:</label>
<meter id="batteryLevel" min="0" max="100" value="35"></meter>
17. Key Differences
| Feature | <progress> |
<meter> |
|---|---|---|
| Primary purpose | Task completion | Measurement |
| Represents progress | Yes | No |
| Represents a scalar value | Not primarily | Yes |
| Can have a maximum | Yes | Yes |
Supports min |
No | Yes |
Supports low |
No | Yes |
Supports high |
No | Yes |
Supports optimum |
No | Yes |
| Indeterminate state | Yes | No |
| Example | File upload | Disk usage |
18. Summary
The HTML <progress> and <meter> elements provide standardized ways to represent numerical information in web pages.
The <progress> element should be used when showing how far a task has progressed toward completion. Examples include downloads, uploads, installations, and course completion.
The <meter> element should be used when representing a measurement within a known range. Examples include battery level, storage usage, scores, ratings, and system capacity.
The most important rule to remember is:
Task completion → <progress>
Measurement → <meter>
Choosing the correct element improves the semantic structure of the HTML document and helps browsers and assistive technologies understand what the displayed value actually represents.