The 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.
The 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. Listboxes contain children whose role is option or elements whose role is group which in turn contain children whose role is option.
It is highly recommended using 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 vertical.
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.
option roleOne or more nested options are required. All selected options have aria-selected set to true. All options that are not selected have aria-selected set to false. If an option is not selectable, omit the aria-selected.
list roleA section containing listitem elements
aria-activedescendantHolds the id string of the currently active element within the listbox. If that's an option element, then that would be the id of the most recently interacted with option, regardless of whether that option has an aria-selected value of true or not. Takes the value of only one id, even in a multiselectable listbox. If the id does not refer to a DOM descendant of the listbox, then that id must be included among the IDs in the aria-owns attribute.
aria-ownsThis is a space-separated list of element IDs which are not DOM child elements of the listbox. IDs listed here cannot also be listed in aria-owns attributes of any other elements.
aria-multiselectableInclude and set to true if the user can select more than one option. If set to true, every selectable option should have an aria-selected attribute included and set to true or false. Options which are not selectable should not have the aria-selected attribute. 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.
aria-requiredA Boolean attribute which indicates that an option with a non-empty string value must be selected.
aria-readonlyThe user cannot change which options are selected or unselected, but the listbox is otherwise operable.
aria-labelA human-readable string value which identifies the listbox. If there's a visible label, then aria-labelledby should be used instead to refer to that label.
aria-labelledbyIdentifies the visible element or elements in a space-separated list of element IDs which identify the listbox. If there's no visible label, then aria-label should be used instead to include a label. (Note: "labelled", with two L's, is the correct spelling based on the accessibility API conventions.)
aria-roledescriptionA human-readable string value which more clearly identifies the role of the listbox. Screen readers will often read this value to the user after reading the label (if there is one), in place of saying "listbox".
When a single-select listbox receives focus:
When a multi-select listbox receives focus:
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:
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.
When the user selects an option, the following must occur:
aria-selected to false, or removing the attribute altogether, changing the appearance of the newly unselected option to appear not selected.aria-selected="true" on the option and changing the appearance of the newly selected option to appear selected.aria-activedescendant value on the listbox to the id of the newly selected optionWhen 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:
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.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.Note: 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.
aria-activedescendantThe snippet below, using aria-activedescendant, 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"
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>const listbox = document.getElementById("listbox1");
listbox.addEventListener("click", listItemClick);
listbox.addEventListener("keydown", listItemKeyEvent);
listbox.addEventListener("keypress", listItemKeyEvent);This could have more easily been handled with the native HTML <select> and <label> elements.
<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><select> with size attribute greater than one.<select> with the attribute size set to greater than "1" and options grouped with optgroup elements.aria-labelledby property set.aria-* properties will need to be set (see ARIA Best Practices).combobox role may be more appropriate.<select> element<label> element<option> elementcombobox roleoption rolelist rolelistitem role