Forms & Controls
HTML <output> element
Represents the result of a calculation or user action. Its for attribute can list the IDs of contributing controls. Associate the result with contributing inputs via for, and provide an accessible label where needed. JavaScript or other application logic must calculate the value; output does not compute it automatically. It accepts global HTML attributes; individual global features may be inapplicable or restricted.
Formal Syntax & Structure
html syntaxhtml
<output name="result">Result</output>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| for | space-separated IDs | Identifies controls that contribute to the output calculation. |
| form | form element ID | Associates an eligible control with a form elsewhere in the same document, overriding an ancestor form where applicable. Does not automatically associate descendants of a fieldset. |
| name | string | Provides an element-specific name: a form field key, radio group name, named frame, metadata key, slot name or other defined purpose. Its meaning depends on the element; it is not a unique DOM identifier. |
Return Value
HTMLOutputElement
Content model: Phrasing content.
Working Example
Example Snippethtml
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>HTML example</title> </head> <body> <form oninput="result.value = Number(amount.value) * 2"> <label> Amount <input id="amount" name="amount" type="number" value="2"> </label> <output name="result" for="amount">4</output> </form> </body></html>