What is <option> element in HTML?

In HTML, the <option> element is used to display a menu or popup item. The items are defined in a <select>, <optgroup>, or <datalist> element.

Syntax

<option label="" value="" selected disabled> option content </option>

Where:

  • label: It takes text as value. It specifies a shorter label that indicates the meaning of the option. In case the label is undefined, its value is the content of the <option> element.
  • value: It takes text as value. It specifies the value that is submitted with the form to the server. In case the value is undefined, its value is the content of the <option> element.
  • selected: It is a Boolean attribute that specifies that an option is selected when loading the page.
  • disabled: It is a Boolean attribute that specifies that an <option> is disabled. The <option> is not selectable if it is set. This makes browsers unable to receive focus-related events like mouse clicks.

In case the <option> element is the descendant of a <select> element, only one single <option> of this <select> element may have the selected attribute, if multiple attributes of <select> is not set.

Example

The following code demonstrates the usage of <option> element in HTML. The content we want to be displayed as option is written within the opening and closing tags <option> and </option>.

  • HTML