docs.rodeo

MDN Web Docs mirror

{{HTMLSidebar}} 

The <option> HTML element is used to define an item contained in a {{HTMLElement("select")}} , an {{HTMLElement("optgroup")}} , or a {{HTMLElement("datalist")}}  element. As such, <option> can represent menu items in popups and other lists of items in an HTML document.

{{InteractiveExample("HTML Demo: &lt;option&gt;", "tabbed-standard")}} 

<label for="pet-select">Choose a pet:</label>

<select id="pet-select">
  <option value="">--Please choose an option--</option>
  <option value="dog">Dog</option>
  <option value="cat">Cat</option>
  <option value="hamster">Hamster</option>
  <option value="parrot">Parrot</option>
  <option value="spider">Spider</option>
  <option value="goldfish">Goldfish</option>
</select>
label {
  font-family: sans-serif;
  font-size: 1rem;
  padding-right: 10px;
}

select {
  font-size: 0.9rem;
  padding: 2px 5px;
}

Attributes

This element includes the global attributes.

Styling with CSS

Styling <option> elements has historically been highly limited. Customizable select elements explains newer features that enable their full customization, just like any regular DOM element.

Legacy option styling

In browsers that don’t support the modern customization features (or legacy codebases where they can’t be used), the styling available on <option> elements depends on the browser and operating system. Depending on the operating system, the font-size of the owning <select> is respected in Firefox and Chromium. Chromium may additionally allow color, background-color, font-family, font-variant, and text-align to be set.

You can find more details about legacy <option> styling in our guide to advanced form styling.

Examples

See {{HTMLElement("select")}}  for examples.

Technical summary

Content categories None.
Permitted content In traditional <select> elements, only text content is permitted, possibly with escaped characters (like &eacute;). In customizable select elements, <option> elements can have any arbitrary content.
Tag omission The start tag is mandatory. The end tag is optional if this element is immediately followed by another <option> element or an `{{HTMLElement("optgroup")}}` , or if the parent element has no more content.
Permitted parents A `{{HTMLElement("select")}}` , an `{{HTMLElement("optgroup")}}`  or a `{{HTMLElement("datalist")}}`  element.
Implicit ARIA role option
Permitted ARIA roles No role permitted
DOM interface `{{domxref("HTMLOptionElement")}}` 

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN