HTML & CSSEasy
What is the <progress> tag?
<progress> displays how far a task has advanced, such as an upload, a download or steps in a form. It takes a value and a max (default 1). Without a value it becomes an indeterminate progress bar, showing that something is happening without knowing how long it will take.
Usage
- Determinate:
<progress value="40" max="100">40%</progress>. - Indeterminate:
<progress></progress>, typically an animated bar. - Text inside the element is the fallback for very old browsers.
- Label it with
<label>oraria-labelledbyso screen readers can name it; it already exposesrole="progressbar"with value information.
<progress> vs <meter>
<progress>: completion of a task over time (0 to done).<meter>: a scalar measurement within a known range, like disk usage, password strength or a battery level, withlow,highandoptimumthresholds.
Styling
It is styled with vendor pseudo-elements:
- Chromium/Safari:
::-webkit-progress-bar,::-webkit-progress-value - Firefox:
::-moz-progress-bar
The simplest cross-browser theming is often just accent-color.
Real-world progress
fetchuploads do not report progress yet in most browsers; useXMLHttpRequest'supload.onprogress, or stream the response body for downloads.- For long tasks, also announce completion with a live region.
Code example
html
1<style>2 body { font-family: system-ui; }3 progress { width: 280px; height: 18px; accent-color: #2b4bff; }4</style>5<label for="upload">Uploading report.pdf</label><br>6<progress id="upload" max="100" value="0">0%</progress>7<output id="pct">0%</output>89<p><label for="wait">Connecting…</label><br><progress id="wait"></progress></p>1011<label for="disk">Disk usage</label>12<meter id="disk" min="0" max="100" low="70" high="90" optimum="20" value="82">82%</meter>1314<p id="status" aria-live="polite"></p>15<script>16 const bar = document.getElementById("upload");17 const timer = setInterval(() => {18 bar.value = Math.min(100, bar.value + 7);19 document.getElementById("pct").textContent = bar.value + "%";20 if (bar.value === 100) {21 clearInterval(timer);22 document.getElementById("status").textContent = "Upload complete";23 }24 }, 250);25</script>
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.