HTML Tags
Advertisements

HTML <option> Tag

Topic: HTML5 Tags ReferencePrev|Next

Description

The <option> element represents an option in a dropdown list defined by the <select> element. A dropdown list must contain at least one <option> element.

The following table summarizes the usages context and the version history of this tag.

Parent: <select>, <optgroup>
Placement: Inline
Content: Text
Start/End Tag: Start tag: required, End tag: optional
Version: HTML 2, 3.2. 4, 4.01, 5

Syntax

The basic syntax of the <option> tag is given with:

HTML / XHTML: <option value="option-value"> ... </option>

Note: In HTML, the end tag for the <option> tag is not mandatory. In XHTML, the <option> tag must be properly closed i.e. both start tag and end tag are required.

The example below shows the <option> tag in action.

<select>
    <option value="ferrari">Ferrari</option>
    <option value="mercedes">Mercedes</option>
   <option value="porsche">Porsche</option>
</select>

Tip: You can use the <optgroup> tag for grouping related options within a dropdown list. It will make your forms more accessible for the users, particularly when the user have to choose from a long list of options.


Tag-Specific Attributes

The following table shows the attributes that are specific to the <option> tag.

Attribute Value Description
label text Specifies a short label for an option.
disabled disabled This Boolean attribute indicates that the enclosed option is disabled i.e. the option is not selectable.
selected selected This Boolean attribute indicates that the option is initially selected.
value option-value Defines a value for an option. If it is not defined, the value of an <option> element is the text content of the element.

Global Attributes

Like all other HTML tags, the <option> tag supports the global attributes in HTML5.


Event Attributes

The <option> tag also supports the event attributes in HTML5.


Browser Compatibility

The <option> tag is supported in all major modern browsers.

Browsers Icon

Basic Support—

  • Firefox 1+
  • Google Chrome 1+
  • Internet Explorer 2+
  • Apple Safari 1+
  • Opera 2.1+

Further Reading

See tutorial on: HTML Forms.

Other form-related tags: <form>, <fieldset>, <legend>, <label>, <input>, <textarea>, <select>, <optgroup>, <button>.

Advertisements
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties