HTML <output> Tag

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

Definition and Usage

The <output> element is a container for a calculation result or the outcome of a user action. Apps usually update it with JavaScript when <input> values change.

Point for at the contributing control ids, and optionally set name or form to associate it with a <form>. The output’s content is not submitted with the form.

Baseline · Widely available.

Core <output> support has been widely available across browsers since about October 2018.

Accessibility note.

Many browsers treat <output> as a live region (role status), so result updates can be announced without moving focus. Prefer plain text inside it.

HTML Syntax

syntax.html
<output for=" id-list">result</output>

Both start and end tags are required. Content is phrasing content (usually text you update from script).

Attributes

The attributes you will use most often on <output>:

AttributeDescriptionTry it
forSpace-separated ids of controls that contributed to the resultTry it
nameName for the form.elements API (not submitted)Try it
formAssociate with a form by that form’s id (even if outside the form)Try it

Global Attributes

The <output> tag also supports the Global Attributes in HTML.

Live Preview

Move the slider or change the number. The <output> shows their sum.

Real controls updating a real <output for="…">.

Result

60

10 + 50 = 60

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Basic Sum with for

Two inputs contribute to one result. Script keeps the output in sync.

HTML
<input type="range" id="b" name="b" value="50"> +
<input type="number" id="a" name="a" value="10"> =
<output id="result" for="a b">60</output>

<script>
  const a = document.getElementById("a");
  const b = document.getElementById("b");
  const result = document.getElementById("result");
  function update() {
    result.value = a.valueAsNumber + b.valueAsNumber;
  }
  a.addEventListener("input", update);
  b.addEventListener("input", update);
</script>
Try It Yourself

How It Works

  1. Give each input an id used in the calculation.
  2. Set for on <output> to those ids (space-separated).
  3. Listen for input on both controls.
  4. Write the sum to output.value (or text content).

Example 2 — Form oninput Shortcut

Update the result from the form when any control inside it changes.

HTML
<form oninput="total.value = Number(x.value) + Number(y.value)">
  <input type="number" id="x" name="x" value="2"> +
  <input type="number" id="y" name="y" value="3"> =
  <output name="total" for="x y">5</output>
</form>
Try It Yourself

How It Works

  1. Wrap controls in a <form>.
  2. Name the output (for example total) so the handler can reach it.
  3. Use oninput to recompute whenever values change.
  4. Remember: output is not submitted — only the inputs are.

Example 3 — Associate with form

Place the result outside the form and still link it with the form attribute.

HTML
<form id="calc">
  <label for="n1">A</label>
  <input type="number" id="n1" name="n1" value="4">
  <label for="n2">B</label>
  <input type="number" id="n2" name="n2" value="6">
</form>

<p>Sum:
  <output form="calc" name="sum" for="n1 n2" id="sumOut">10</output>
</p>
Try It Yourself

How It Works

  1. Give the form an id.
  2. Set form="that-id" on the output outside the form.
  3. Keep for pointing at the input ids.
  4. Update from script the same way as an in-form output.

Example 4 — Labeled Result

<output> is labelable — give the result a clear accessible name.

HTML
<label for="price">Price</label>
<input type="number" id="price" name="price" value="20">
<label for="qty">Qty</label>
<input type="number" id="qty" name="qty" value="3">

<label for="lineTotal">Line total</label>
<output id="lineTotal" for="price qty">60</output>
Try It Yourself

How It Works

  1. Label every input as usual.
  2. Label the output too with matching for / id.
  3. Multiply (or otherwise compute) in script on input.
  4. Keep the announced text short so live-region updates stay clear.

Edge Cases & Pitfalls

Most surprises come from expecting output to submit, or from forgetting to update it in script.

forms

Not submitted

Output name and contents are left out of form posts. Persist the real inputs (or compute again on the server).

for

for does not calculate

It documents relationships. You still write the math in JavaScript (or oninput).

a11y

Keep live text simple

Announcements are usually plain text. Avoid stuffing links or complex widgets inside output.

types

Coerce numbers

Input values are strings. Use Number(...) or valueAsNumber before adding.

naming

Prefer output over span

For form results, <output> carries clearer semantics than a generic <span>.

Browser Support

The <output> element is core HTML form UI in modern browsers. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<output>

Widely available since about October 2018. Chrome, Firefox, Safari, Edge, and Opera support output, including for/form/name associations.

96% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer No
Not supported
<output> Widely supported

Bottom line: Safe for modern sites. Update results with script, and never rely on output being submitted.

Key Takeaways

  • Role: <output> shows a calculation or action result.
  • Wire: use for to list contributing control ids; update with script.
  • Forms: content is not submitted; associate with form if needed.
  • Access: label it and keep announced text plain.

One line: put live results in <output>, compute them in script, submit the inputs.

Default CSS Settings

User agents typically treat output as inline phrasing content:

default.css
output {
  display: inline;
}

Style it lightly for emphasis if needed. Do not remove focus outlines from related controls.

Frequently Asked Questions

The output element is a container for a calculation result or the outcome of a user action — for example the sum of two inputs shown live as the user changes values.
No. The output element’s name and contents are not included in form submission. Submit the underlying inputs if the server needs those values.
for lists space-separated id values of controls that contributed to the result. It documents the relationship for authors and assistive tech; it does not calculate anything by itself.
Use JavaScript (or a form oninput handler) to set the element’s textContent or the .value property when inputs change.
Many browsers expose output as a live region (implicit role status), so result changes can be announced without moving focus. Keep the content plain and clear.
Prefer output when the text is a form-related result. It is labelable, form-associated, and conveys intent better than a generic span.

Next: p

Learn the paragraph element for ordinary body text.

p tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful