Rule n° 93 - The items in a drop-down list are grouped together appropriately, where applicable.
The content of some drop-down lists is sufficiently homogeneous to be sufficient in itself, but in some cases, the list will be easier to see by being better organized. In this case, the optgroup html element is your friend.
Goal
- Allow technical aids to return a list to the user whose organization is clear to see; and that simplifies moving from one item on the list to another.
- Foster the accurate rendering of complex drop-down lists in every browser.
- Improve the accessibility of content for people with disabilities.
Solution technique
Use the optgroup element to tag thematic groupings of option elements in select
Use the label attribute of the optgroup element to display the label for each grouping.
Moyen de contrôle
For each drop-down list:
- Open each (
select) list to identify those which require a grouping ofoptionelements, for example grouping of car models by brands or grouping of cities by administrative area; - Verify, by examining the source code using Firebug, that each series of
optionelements that should be grouped is tagged with theoptgroupelement; - Check that each
optgroupelement has alabelattribute associating a label relevant to the group of options in question.