HTML Reference ยท Forms
The <output> element
Reference for the HTML <output> element: showing the result of a calculation or user action, the for, form and name attributes, live announcements and technical details.
The <output> element holds the result of a calculation or user action: a total price, a converted unit, the current value of a slider. A script normally writes into it. Its for attribute lists the controls the result depends on, which documents the relationship for scripts and assistive technology.
<label for="km">Kilometers</label> <input type="number" id="km" value="5"> = <output id="miles" for="km">3.11</output> miles
Try it
The input event on the form fires for every change inside it, so one listener keeps both outputs current. Pressing Reset restores each output to its original text, because outputs are resettable.
Attributes
| Attribute | Values | Description |
|---|---|---|
for |
Space-separated list of element IDs | The controls whose values went into the result. |
form |
ID of a <form> |
Associates the output with a form elsewhere in the document. |
name |
Text | A name for scripts, available through form.elements. The output's value is not submitted. |
It also accepts the global attributes.
Usage notes
- Not submitted. Even with a
name, an output is left out of the form data. If the server needs the result, recalculate it there (never trust a total sent by the browser anyway). - Live by default. Its implicit role is
status, a polite live region, so many screen readers announce changes without you addingaria-live. Avoid updating it on every keystroke if that would be noisy. valuevsdefaultValue. Settingoutput.valuechanges the text; the original content is kept asdefaultValueand restored on form reset.- Label it. An output is labelable, so a
<label>can name it, as with "Total" in the example. - Not for static text. If a number never changes, a regular element or
<data>is enough.
Technical summary
| Content categories | Flow content, phrasing content, palpable content; form-associated: listed, labelable, resettable (not submittable) |
| Permitted content | Phrasing content |
| Tag omission | None; both the start and end tags are required |
| Permitted parents | Any element that accepts phrasing content |
| Implicit ARIA role | status |
| DOM interface | HTMLOutputElement |
| Default display | inline |
Browser support
Supported in every current browser.
Related
<meter>and<progress>โ visual gauges<input>types โ sliders often paired with an output<form>โ theinputevent and reset- Lesson: Output, Meter and Progress
- Lesson: ARIA Roles, States and Properties