listbox role is used for lists from which a user may select one or more items which are static and, unlike HTML <select> elements, may contain images.
listbox role is used to identify an element that creates a list from which a user may select one or more static items, similar to the HTML <select> element. Unlike <select>, a listbox can contain images. Each child of a listbox should have a role of option.
It is highly recommended to use the HTML select element, or a group of radio buttons if only one item can be selected, or a group of checkboxes if multiple items can be selected, because there is a lot of keyboard interactivity to manage focus for all the descendants, and native HTML elements provide this functionality for you for free.
Elements with the role
listbox have an implicit
aria-orientation value of
When a list is tabbed to, the first item in the list will be selected if nothing else already is. Up/down arrows navigate the list, and pressing Shift + Up/Down arrows will move and extend the selection. Typing one or more letters will navigate the list items (same letter goes to each item starting with that, different letters go to the first item starting with that entire string). If the current item has an associated context menu, Shift+F10 will launch that menu. If list items are checkable, Space can be used to toggle checkboxes. For selectable list items, Space toggles their selection, Shift+Space can be used to select contiguous items, Ctrl+Arrow moves without selecting, and Ctrl+Space can be used to select non-contiguous items. It is recommended that a checkbox, link or other method be used to select all items, and Ctrl+A could be used as a shortcut key for this.
When the listbox role is added to an element, or such an element becomes visible, screen readers announce the label and role of the listbox when it gets focus. If an option or item is focused within the list, it gets announced next, followed by an indication of the item's position with the list if the screen reader supports this. As focus moves within the list, the screen reader announces the relevant items.
Associated ARIA roles, states, and properties
- One or more nested options are required. All selected options have
true. All options that are not selected have
false. If an option is not selectable, omit the
- A section containing
States and Properties
- Include and set to true the user can select more than one option. If set to true, every option should have a the aria-selected attribute included. If false or omitted, only the currently selected option, if any option is selected, needs the aria-selected attribute, and it must be set to true.
- Takes as its value the i
dof the currently active option, meaning the most recently interacted with option, whether that option has an
false. Takes the value of only one id, even in a multiselect,
- The listbox is not editable -- the user can not change which options are selected or unselected -- but is otherwise operable.
- When a single-select listbox receives focus:
- If none of the options are selected before the listbox receives focus, the first option receives focus. Optionally, the first option may be automatically selected.
- If an option is selected before the listbox receives focus, focus is set on the selected option.
- When a multi-select listbox receives focus:
- If none of the options are selected before the listbox receives focus, focus is set on the first option and there is no automatic change in the selection state.
- If one or more options are selected before the listbox receives focus, focus is set on the first option in the list that is selected.
- Down Arrow: Moves focus to the next option. Optionally, in a single-select listbox, selection may also move with focus.
- Up Arrow: Moves focus to the previous option. Optionally, in a single-select listbox, selection may also move with focus.
- Home (Optional): Moves focus to first option. Optionally, in a single-select listbox, selection may also move with focus. Supporting this key is strongly recommended for lists with more than five options.
- End (Optional): Moves focus to last option. Optionally, in a single-select listbox, selection may also move with focus. Supporting this key is strongly recommended for lists with more than five options.
- Type-ahead is recommended for all listboxes, especially those with more than seven options:
- Type a character: focus moves to the next item with a name that starts with the typed character.
- Type multiple characters in rapid succession: focus moves to the next item with a name that starts with the string of characters typed.
- Multiple Selection: Authors may implement either of two interaction models to support multiple selection: a recommended model that does not require the user to hold a modifier key, such as Shift or Control, while navigating the list or an alternative model that does require modifier keys to be held while navigating in order to avoid losing selection states.
- Recommended selection model -- holding modifier keys is not necessary:
- Space: changes the selection state of the focused option .
- Shift + Down Arrow (Optional): Moves focus to and toggles the selected state of the next option.
- Shift + Up Arrow (Optional): Moves focus to and toggles the selected state of the previous option.
- Shift + Space (Optional): Selects contiguous items from the most recently selected item to the focused item.
- Control + Shift + Home (Optional): Selects the focused option and all options up to the first option. Optionally, moves focus to the first option.
- Control + Shift + End (Optional): Selects the focused option and all options down to the last option. Optionally, moves focus to the last option.
- Control + A (Optional): Selects all options in the list. Optionally, if all options are selected, it may also unselect all options.
- Recommended selection model -- holding modifier keys is not necessary:
selecting an option in a single select listbox
When the user selects an option, the following must occur:
- Deselect the previously selected option, setting the aria-selected to false, or removing the attribute altogether, changing the appearance of the newly unselected option to appear not selected.
- Select the newly selected option, setting aria-selected="true" on the option and changing the appearance of the newly selected option to appear selected.
- Update the
aria-activedescendantvalue on the listbox to the id of the newly selected option
- Visually handle the blur, focus, and selected states of the option
Toggling the state of an option in a multi select listbox
When the user clicks on an option, hits Space when focused on an option, or otherwise toggles the state of an option, the following must occur:
- Toggle the aria-selected state of the currently focused option, changing the state of the aria-selected to true if it was false or false if it was true.
- Change the appearance of the option to reflect it's selected state
- Update the aria-activedescendant value on the listbox to the id of the option the user just interacted with, even if they toggled the option to be unselected.
The first rule of ARIA use is you can use a native feature with the semantics and behavior you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible, then do so. The <select> element with descendant <option> elements handles all the needed interactions natively.
Example 1: A single select listbox that uses aria-activedescendant
The snippet below shows how the listbox role is added directly into the html source code.
<p id="listbox1label" role="label">Select a color:</p> <div role="listbox" tabindex="0" id="listbox1" aria-labelledby="listbox1label" onclick="return listItemClick(event);" onkeydown="return listItemKeyEvent(event);" onkeypress="return listItemKeyEvent(event);" aria-activedescendant="listbox1-1"> <div role="option" id="listbox1-1" class="selected" aria-selected="true">Green</div> <div role="option" id="listbox1-2">Orange</div> <div role="option" id="listbox1-3">Red</div> <div role="option" id="listbox1-4">Blue</div> <div role="option" id="listbox1-5">Violet</div> <div role="option" id="listbox1-6">Periwinkle</div> </div>
<label for="listbox1">Select a color:</label> <select id="listbox1"> <option selected>Green</option> <option>Orange</option> <option>Red</option> <option>Blue</option> <option>Violet</option> <option>Periwinkle</option> </select>
- Scrollable Listbox Example: Single-select listbox that scrolls to reveal more options, similar to HTML
sizeattribute greater than one.
- Collapsible Dropdown Listbox Example: Single-select collapsible listbox that expands when activated, similar to HTML
selectwith the attribute
- Example Listboxes with Rearrangeable Options: Examples of both single-select and multi-select listboxes with accompanying toolbars where options can be added, moved, and removed.
- To be keyboard accessible, authors should manage focus of all descendants of this role.
- It is recommended that authors use different styling for the selection when the list is not focused, e.g. a non-active selection is often shown with a lighter background colour.
- If the listbox is not part of another widget, it should have the
- If one or more entries are not DOM children of listbox, additional aria-* properties will need to be set (see ARIA Best Practices).
- If there is a valid reason to expand the listbox, the
comboboxrole may be more appropriate.
|Accessible Rich Internet Applications (WAI-ARIA) 1.1
The definition of 'ARIA listbox role' in that specification.
|WAI-ARIA Authoring Practices 1.1
The definition of 'Listbox Role' in that specification.
Screen reader support