--- title: HTMLOptionElement slug: Web/API/HTMLOptionElement translation_of: Web/API/HTMLOptionElement ---
{{APIRef("HTML DOM")}}

The HTMLOptionElement interface represents {{HTMLElement("option")}} elements and inherits all classes and methods of the {{domxref("HTMLElement")}} interface.

{{InheritanceDiagram(600, 120)}}

Properties

Inherits properties from its parent, {{domxref("HTMLElement")}}.

{{domxref("HTMLOptionElement.defaultSelected")}}
Is a {{domxref("Boolean")}} that contains the initial value of the {{htmlattrxref("selected", "option")}} HTML attribute, indicating whether the option is selected by default or not.
{{domxref("HTMLOptionElement.disabled")}}
Is a {{domxref("Boolean")}} representing the value of the {{htmlattrxref("disabled", "option")}} HTML attribute, which indicates that the option is unavailable to be selected. An option can also be disabled if it is a child of an {{HTMLElement("optgroup")}} element that is disabled.
{{domxref("HTMLOptionElement.form")}} {{readonlyInline}}
Is a {{domxref("HTMLFormElement")}} representing the same value as the form of the corresponding {{HTMLElement("select")}} element, if the option is a descendant of a {{HTMLElement("select")}} element, or null if none is found.
{{domxref("HTMLOptionElement.index")}} {{readonlyInline}}
Is a long representing the position of the option within the list of options it belongs to, in tree-order. If the option is not part of a list of options, like when it is part of the {{HTMLElement("datalist")}} element, the value is 0.
{{domxref("HTMLOptionElement.label")}} {{readonlyInline}}
Is a {{domxref("DOMString")}} that reflects the value of the {{htmlattrxref("label", "option")}} HTML attribute, which provides a label for the option. If this attribute isn't specifically set, reading it returns the element's text content.
{{domxref("HTMLOptionElement.selected")}}
Is a {{domxref("Boolean")}} that indicates whether the option is currently selected.
{{domxref("HTMLOptionElement.text")}}
Is a {{domxref("DOMString")}} that contains the text content of the element.
{{domxref("HTMLOptionElement.value")}}
Is a {{domxref("DOMString")}} that reflects the value of the {{htmlattrxref("value", "option")}} HTML attribute, if it exists; otherwise reflects value of the {{domxref("Node.textContent")}} property.

Methods

Inherits methods from its parent, {{domxref("HTMLElement")}}.

Option()
Is a constructor creating an HTMLOptionElement object. It has four values: the text to display, text, the value associated, value, the value of defaultSelected, and the value of selected. The last three values are optional.

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', "#htmloptionelement", "HTMLOptionElement")}} {{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C', "forms.html#the-option-element", "HTMLOptionElement")}} {{Spec2('HTML5 W3C')}} A constructor, Option(), has been added.
The form property can be the null value.
{{SpecName('DOM2 HTML', 'html.html#ID-70901257', 'HTMLOptionElement')}} {{Spec2('DOM2 HTML')}} The selected property changed its meaning: it now indicates if the option is currently selected and no longer if it was initally selected.
The defaultSelected property is no longer read-only.
{{SpecName('DOM1', 'level-one-html.html#ID-70901257', 'HTMLOptionElement')}} {{Spec2('DOM1')}} Initial definition

Browser compatibility

{{Compat("api.HTMLOptionElement")}}

See also