Skip to content
Tutorials Center
My learning

Topics

Lesson 72 of 122 Β· Forms

Output, Meter and Progress

Show calculated results with output, measurements within a known range with meter, and task completion with progress, including indeterminate progress bars.

Forms are not only about collecting input. Sometimes you need to show something back: the total of an order, how full a storage quota is, or how far along an upload has got. HTML has three small elements for exactly these jobs: <output>, <meter> and <progress>.

They are easy to confuse, especially the last two, which both draw a bar. In this lesson you will learn what each one means, how to use it, and how to choose between them.

<output>: the result of a calculation

<output> holds the result of a calculation or a user action. Think of a price total, a loan payment, or the current value of a slider. Its for attribute lists the ids of the controls that the result depends on, separated by spaces:

HTML
<label for="width">Width (m)</label>
<input type="number" id="width" name="width" value="4">

<label for="length">Length (m)</label>
<input type="number" id="length" name="length" value="5">

<p>Floor area: <output id="area" for="width length">20</output> mΒ²</p>

<output> does not calculate anything by itself; a script fills it in. What it adds is meaning:

  • for records which inputs produced the result.
  • Browsers expose an output to assistive technology as a status region, so many screen readers announce its new content when it changes, without moving focus.
  • It is a form-associated element: it belongs to a form, can take a name and a form attribute, and you can reach it through form.elements. It is not submitted, though. Its contents are for people, not servers.

Updating an output

The easiest way to keep an output in sync is to listen for the input event on the whole form. That event bubbles up from every control, so one listener covers them all:

A live total with output

Change the numbers or drag the slider and the outputs update immediately. Setting output.value replaces its text content. The second output is the classic companion for a range slider, which otherwise gives no hint of its exact value.

You will also see oninput attributes used for this in older examples, such as <form oninput="...">. That works, but listeners in a script are easier to maintain, as Event Attributes and Event Listeners explains.

<meter>: a measurement within a known range

<meter> shows a scalar measurement inside a known range: disk usage, a battery level, a relevance score, the strength of a password. It is a gauge. The value can go up and down, and it is not "finished" at any point.

HTML
<label for="disk">Disk usage</label>
<meter id="disk" min="0" max="512" value="371">371 GB of 512 GB used</meter>

The text between the tags is fallback content for very old browsers. Modern browsers draw a bar instead, so make sure the meter has a label, or describe the value in nearby text, so everyone can read the actual number.

low, high and optimum

Three more attributes divide the range into regions and say which region is good. Browsers color the bar accordingly, typically green, yellow or red:

  • low: the upper end of the "low" region.
  • high: the lower end of the "high" region.
  • optimum: where the ideal value sits. Its position decides which region counts as good.

Where optimum sits changes everything:

  • Optimum in the high region (higher is better): a battery level, a test score. High values are green, low ones red.
  • Optimum in the low region (lower is better): disk usage, page weight. Low values are green, high ones red.
  • Optimum in the middle: room temperature, humidity. The middle is green, both extremes are worse.
Meters with low, high and optimum

All three meters show the same value, set by the slider, yet they react differently to it. At 15%, the battery is in its bad zone while the storage meter is happy; drag to 95% and it is the other way round. Humidity is only happy in the middle. The exact colors vary by browser.

min defaults to 0 and max to 1, so <meter value="0.6"></meter> is a 60% gauge. Values outside the range are clamped to it.

<progress>: how much of a task is done

<progress> shows completion of a task: a file upload, a multi-step form, an installation. It only moves forward, and it ends when the task is finished.

It has just two attributes:

  • max: the total amount of work (default 1).
  • value: how much is done so far, between 0 and max.
HTML
<label for="upload">Uploading report.pdf</label>
<progress id="upload" max="100" value="40">40%</progress>

There is no min, and no low, high or optimum. Progress is simply "this much done".

Indeterminate progress

Sometimes you know a task is running but not how long it will take, for example while waiting for a server response. Leave out the value attribute and the bar becomes indeterminate: browsers show an animated "busy" bar instead of a fill level. You can style that state with the :indeterminate pseudo-class. Setting a value in JavaScript turns it into a normal, determinate bar; to go back, remove the attribute with removeAttribute("value").

Determinate and indeterminate progress

Press Start download to watch the first bar fill up, while the second stays in its busy animation because it has no value.

Label your progress bars. A bar on its own tells a screen reader user nothing. Connect a <label> as in the examples, or use aria-labelledby to point at a heading. For long tasks, also update some visible text, such as the percentage, so people do not have to guess from the bar's length.

Meter or progress?

The two bars look alike, so ask what the number means:

Question Use
How much of a task is finished? Will it reach 100% and stop? <progress>
How big is a quantity inside a known range? Can it go up and down? <meter>
Is it a number computed from other inputs, shown as text? <output>

A file upload is progress. Free space on the disk you upload to is a meter. The upload's estimated time remaining, calculated by a script, could go in an output.

Do not use <meter> for a value with no known maximum, such as a count of visitors. A meter needs a range to be meaningful. And do not use either bar for decoration; if there is no real measurement behind it, use CSS instead.

Styling, briefly

Both bars use the browser's native look by default. accent-color (from Checkboxes and Radio Buttons) recolors the fill of <progress> in most browsers. Deeper customization means turning off the native look with appearance: none and styling browser-specific pseudo-elements, which differ between engines. If you go down that road, test in every browser you support, and keep the label and the visible number.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. Which element fits a bar showing how much of a file upload has finished?

    Progress describes completion of a task that ends at 100%. A meter is a gauge for a measurement within a range.
  2. 2. How do you make a progress bar indeterminate?

    Without a value, the bar shows an animated busy state. A value of 0 is a determinate bar at 0%, and there is no indeterminate attribute.
  3. 3. A meter shows disk usage, where less is better. Where should optimum go?

    The position of optimum decides which region counts as good. For disk usage, low values are best.
  4. 4. Is the content of an <output> element submitted with its form?

    An output belongs to a form and can have a name, but its value is never part of the submitted data. Use a hidden input if the server needs it.

Summary

  • <output> shows a computed result; for lists the controls it depends on, and screen readers can announce its changes. It is not submitted.
  • <meter> is a gauge for a measurement within a known range; low, high and optimum define which values are good.
  • <progress> shows how much of a task is done, with value and max; without a value it is indeterminate.
  • Always label meters and progress bars, and show the actual number in text as well.
  • Choose by meaning: completion is progress, a measurement is meter, a calculated value is output.

That completes the forms chapter. Next up: Collapsible Sections with Details, the first of HTML's built-in interactive elements.