HTML Tutorial

HTML Tag: <option>

The <option> tag is used to create options in a <select> dropdown list. It defines the text and value of each option.

Usage of <option>

To create an <option> tag, use the following syntax:

<option value="value">text</option>

where:

  • value is the value of the option (optional)
  • text is the text displayed for the option

Attributes of <option>

The <option> tag supports the following attributes:

  • value: Specifies the value of the option.
  • selected: Indicates whether the option is selected by default.
  • disabled: Disables the option, making it unselectable.
  • label: Associates a label with the option.

Examples with <option>

  1. Single option:
<option value="option1">Option 1</option>
  1. Selected option:
<option value="option2" selected>Option 2</option>
  1. Disabled option:
<option value="option3" disabled>Option 3</option>

Exploring the <option> tag (Example)

<form>
  <label for="options">Select an option:</label>
  <select id="options">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3" selected>Option 3</option>
  </select>
  <input type="submit" value="Submit">
</form>

In this example, the <option> tag is used to create three options in a dropdown list. The third option is selected by default using the selected attribute.