option Element


 

Module

The option element is declared by the XHTML 1.1 Forms Module

Elements in the Forms Module are:
form | label | textarea | select | optgroup | option | button | fieldset | legend |
input type="button" | input type="checkbox" | input type="file" | input type="hidden" | input type="image" | input type="password" | input type="radio" | input type="reset" | input type="submit" | input type="text"

Description

An option element is used to specify an individual choice within a select list. When the list is rendered by the browser, it is the content of the option element which is displayed to the user.

Its selected attribute may be specified to state that the option should be pre-selected within the select list when the form is first rendered. For a select list without the multiple attribute specified, only one of its option elements may have the selected attribute specified.

The value attribute specifies the value to be sent to the form processor to represent that option when it is selected. If a value attribute is not present, the content of the option element is used instead.

Here is a very simple select list:

<label for="colour">Colour:</label>
<select id="colour" name="colour">
  <option value="1">Black</option>
  <option value="2" selected="selected">Red</option>
  <option value="3">Blue</option>
</select>

This renders as:

Groups of option elements may be created within a single select list using optgroup elements.

#REQUIRED Attributes

There are no #REQUIRED attributes on the option element.


Specific Attributes

Specific attributes of the option element are listed below:

From the Forms Module - the Element's own Module

disabled [ type Boolean ]
If this attribute is present, the option is initially disabled. The user cannot interact with a disabled control. (Unsupported in IE7 and below for optgroup and option.)
label [ type Text ]
May be used to specify a short label for the option, to be used by the user agent instead of the contents of the option element (this attribute is inconsistently supported - e.g. currently Opera uses it but Firefox does not)
selected [ type Boolean ]
If this attribute is present, the option is pre-selected within the select list, otherwise it is not (this is its initial value - to which it is returned if the form is reset)
value [ type CDATA ]
The value sent to the form processor to represent that option when it is selected - if not present, the contents of the option element are used

Common Attributes

Common attributes of the option element are listed below:

From the Core Attribute Collection

class [ type NMTOKENS ]
One or more space separated classes
id [ type ID ]
A unique identifier for the element
style [ type CDATA ], from the Style Attribute Module (deprecated)
Element-specific styles
title [ type Text ]
Descriptive title for the element (in some user agents this may appear as a "tooltip" when the mouse hovers over the element)
xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]
XML namespace

From the I18N Attribute Collection

dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Module
Left-to-right or right-to-left directionality
xml:lang [ type LanguageCode ]
A language code for the element

From the Events Attribute Collection

All attributes in the Events Attribute Collection are supported:
onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup


Content Model

The Content Model for the option element is:

#PCDATA

See Content Model & Nesting for information about Content Model syntax and Nesting Groups.

Valid children of option

Valid parents of option


Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 01 Oct 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > XHTML 1.1 Indexes > Element Index (XHTML 1.1) > option Element