Create Groups in a Drop-Down List Box
Page 1 of 2
Written by
Gregory Scot Collins
Saturday, 17 June 2006, 5:57 AM
This article has been tested to work with the following products and versions. No guarantee of compatibility, with or without modification, is offered for products or versions other than those listed.
- Internet Explorer 7.0 and 6.0 (Microsoft)
- FireFox 2.0 and 1.5 (Mozilla)
- CSS 2.0 and 1.0 (W3C)
- HTML 4.01 (W3C)
Grouping items in a drop-down list box is easy with the optgroup element. The optgroup element is a child to the select element and has two attributes: label (required) and disabled (optional). The required label attribute specifies the text that will appear as a header to the contained group of options. Many browsers render the label text in bold italic. The optional disabled attribute is used to render the entire group of options non-selectable to the user. Options within an option group are indented. Listing 1 shows an example of how to use the optgroup element:
In HTML 4.0, an optgroup element can only contain option elements. In other words, option groups cannot be nested. This may change in a future version of HTML.



Stumble It!
Digg It!
del.icio.us




