optgroup Element


 

Module

The optgroup element is declared by the XHTML 1.1 Forms Module but is not present in the *W3C XHTML 1.1 Basic 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

The optgroup element is used to group a set of option elements within a select list. The mandatory label attribute is used to assign a title for the group which will be visible to the user. Bear in mind, however, that not all user agents support optgroup so your options should make sense even if the optgroup labels are not rendered.

For example:

<label for="animal">Which of these animals do you like best?</label>
<select id="animal" name="animal">
  <optgroup label="Mammals">
    <option value="1" selected="selected">Hippopotamus</option>
    <option value="2">Elephant</option>
    <option value="3">Lion</option>
    <option value="4">Giraffe</option>
  </optgroup>
  <optgroup label="Reptiles">
    <option value="5">Crocodile</option>
    <option value="6">Iguana</option>
    <option value="7">Tortoise</option>
    <option value="8">Snake</option>
  </optgroup>
</select>

This renders as:

For the selection of "Iguana" above, the name=value pair of animal=6 will be sent to the processing URI if the select list data is submitted as part of an enclosing form.

#REQUIRED Attributes

The label attribute is #REQUIRED on the optgroup element.


Specific Attributes

Specific attributes of the optgroup element are listed below:

From the Forms Module - the Element's own Module

disabled [ type Boolean ]
If this attribute is present, the optgroup is initially disabled. The user cannot interact with a disabled control. (Unsupported in IE7 and below for optgroup and option.)
label [ type Text - #REQUIRED ]
A label for the optgroup, to be rendered within the select list

Common Attributes

Common attributes of the optgroup 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 optgroup element is:

option+

NOTE: This element cannot be empty

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

Valid children of optgroup

Valid parents of optgroup


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) > optgroup Element