listbox
Example
<ul>
<li onclick="pick(this)">Red</li>
<li onclick="pick(this)">Blue</li>
</ul><ul role="listbox" aria-label="Color" tabindex="0" aria-activedescendant="c1">
<li role="option" id="c1" aria-selected="true">Red</li>
<li role="option" id="c2" aria-selected="false">Blue</li>
</ul>The list becomes a focusable listbox with option roles and selection state, ready for arrow key handling.
Common mistakes
- Using
role='listbox'for a plain list of links or cards. - Putting interactive elements, like delete buttons, inside options.
Key points
- Every child of the
listboxhasrole='option', and options contain no buttons or links. - Focus is managed with
aria-activedescendantor rovingtabindex, and arrow keys move it. - Selected options have
aria-selected='true'; multi-select lists setaria-multiselectable='true'. - A native
<select>is used when the design allows.
Interview questions
Does the select element have the listbox role?
Yes, when it has multiple or a size greater than 1. A single-choice dropdown <select> maps to combobox.
Can a listbox option contain a button?
No. Options cannot contain interactive elements; use a grid if each row needs its own controls.