| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/HTMLOutputElement | [Back] [Original] |
Get to know MDN better
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The HTMLOutputElement() constructor creates a new HTMLOutputElement object.
Note:
Currently only Safari implements this constructor, so using Document.createElement() is recommended for broader compatibility see the example below.
new HTMLOutputElement()
None.
A new HTMLOutputElement object.
TypeErrorThrown with the message "Illegal constructor" in browsers that do not support this constructor.
Note:
In practice, you would usually create <output> elements using Document.createElement() instead of this constructor, since createElement() is supported across all browsers.
This example creates an <output> element using the HTMLOutputElement() constructor and inserts it into a form that adds two numbers together.
<form id="my-form">
<label>
Number one
<input type="number" id="a" value="5" />
</label>
+
<label>
Number two
<input type="number" id="b" value="3" />
</label>
=
<span id="output-container"></span>
</form>
<p id="warning" hidden>
Your browser does not support the
<code>HTMLOutputElement()</code> constructor.
</p>
body {
font-family: system-ui;
}
input {
width: 3rem;
font-size: inherit;
}
p {
padding: 0.25rem;
background-color: #fff2cc;
}
try {
new HTMLOutputElement();
} catch {
document.getElementById("warning").hidden = false;
}
const output = new HTMLOutputElement();
output.id = "result";
output.setAttribute("for", "a b");
document.getElementById("output-container").appendChild(output);
function updateResult() {
const a = document.getElementById("a");
const b = document.getElementById("b");
output.value = a.valueAsNumber + b.valueAsNumber;
}
document.getElementById("my-form").addEventListener("input", updateResult);
updateResult();
| Specification |
|---|
| HTML # htmloutputelement |
This page was last modified on Mar 23, 2026 by MDN contributors.
HTMLOutputElementBeforeUnloadEventDOMStringMapErrorEventHTMLAnchorElementHTMLAreaElementHTMLAudioElementHTMLBRElementHTMLBaseElementHTMLBodyElementHTMLButtonElementHTMLCanvasElementHTMLDListElementHTMLDataElementHTMLDataListElementHTMLDialogElementHTMLDivElementHTMLDocumentHTMLElementHTMLEmbedElementHTMLFieldSetElementHTMLFormControlsCollectionHTMLFormElementHTMLFrameSetElementHTMLGeolocationElementHTMLHRElementHTMLHeadElementHTMLHeadingElementHTMLHtmlElementHTMLIFrameElementHTMLImageElementHTMLInputElementHTMLLIElementHTMLLabelElementHTMLLegendElementHTMLLinkElementHTMLMapElementHTMLMediaElementHTMLMenuElementHTMLMetaElementHTMLMeterElementHTMLModElementHTMLOListElementHTMLObjectElementHTMLOptGroupElementHTMLOptionElementHTMLOptionsCollectionHTMLParagraphElementHTMLPictureElementHTMLPreElementHTMLProgressElementHTMLQuoteElementHTMLScriptElementHTMLSelectElementHTMLSourceElementHTMLSpanElementHTMLStyleElementHTMLTableCaptionElementHTMLTableCellElementHTMLTableColElementHTMLTableElementHTMLTableRowElementHTMLTableSectionElementHTMLTemplateElementHTMLTextAreaElementHTMLTimeElementHTMLTitleElementHTMLTrackElementHTMLUListElementHTMLUnknownElementHTMLVideoElementHashChangeEventHistoryImageDataLocationMessageChannelMessageEventMessagePortNavigatorPageRevealEventPageSwapEventPageTransitionEventPluginPluginArrayPromiseRejectionEventRadioNodeListTimeRangesUserActivationValidityStateWindowWorkletGlobalScopeYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |