NOTICE: This website is no longer updated or supported - as such many of the techniques used to build it may seem antiquated in the modern day. It is preserved for historical reasons only.

HTML XHTML The Complete Reference
home » reference » appendix a » html element reference

<option> (Option in Selection List)


This element specifies an item in a selection list defined by the select element.

Standard Syntax


<option
class="class name(s)"
dir="ltr | rtl"
disabled="disabled"
id="unique alphanumeric identifier"
label="text description"
lang="language code"
selected="selected"
style="style information"
title="advisory text"
value="option value">
</option>

Attributes Defined by Internet Explorer


language="javascript | jscript | vbs | vbscript"(4)

Standard Event Attributes


onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmouseomove, onmouseout, onmouseover, onmouseup

Events Defined by Internet Explorer


onlayoutcomplete, onlosecapture, onpropertychange, onreadystatechange, onselectstart, ontimeerror

Element Specific Attributes


disabled
Presence of this attribute indicates that the particular item is not selectable. Traditional HTML did not require a value for this attribute, but it should be set to disabled under XHTML.


label
This attribute contains a short label that might be more appealing to use when the selection list is rendered as a hierarchy due to the presence of an optgroup element.


selected
This attribute indicates that the associated item is the default selection. If not included, the first item in the selection list is the default. If the select element enclosing the option elements has the multiple attribute, the selected attribute might occur in multiple entries. Otherwise, it should occur in only one entry. Under XHTML, the value of the selected attribute must be set to selected.


value
This attribute indicates the value to be included with the form result when the item is selected.


Example


Which is your favorite dog?
<select>
  <option value="Scotty">Angus</option>
  <option value="Golden Retriever">Borrego</option>
  <option value="Choco Lab">Dutch</option>
  <option value="Mini Schnauzer" selected="selected">Tucker</option>
</select>

Compatibility


HTML 2, 3.2. 4, 4.01
XHTML 1.0, 1.1, Basic
Internet Explorer 2, 3, 4, 5, 5.5, 6
Netscape 1, 2, 3, 4, 4.5 – 4.8, 6, 7
Opera 4-7

Notes


Under HTML specifications, the closing tag for <option> is optional. However, for XHTML compatibility the closing tag </option> is required.

This element should occur only within the context of a select element.

The HTML 2.0 and 3.2 specifications define only the selected and value attributes for this element.

(X)HTML Elements
CSS Properties
Previous: option Next: p
< Home | About | Chapters | Examples | Errata | Reference | Site Map >