focusgroup
This feature is not (yet) supported on your device
The focusgroup HTML attribute is a declarative way to add keyboard arrow-key navigation to widgets like
toolbars, tablists, menus, listboxes, etc. without the need for JavaScript.
The attribute takes a behavior token and three optional modifier tokens:
focusgroup="[behavior] [modifier1] [modifier2] [modifier3]"
The behavior token defines the widget pattern and can take the values:
toolbartablistradiogrouplistboxmenumenubarnone
The first modifier defines the navigation direction and can take the values block (vertical) or
inline (horizontal).
The second modifier defines the wrapping behavior and can take the values wrap (allow navigation to
wrap around) or nowrap (prevent navigation from wrapping). When set to wrap, the
navigation will wrap around to the next item in the group, so when the last item is reached, the focus will move to
the first item in the group and vice versa. When set to nowrap, the navigation will stop at the last
item and the focus will remain on the last item.
The third modifier defines if the last-focused item in a group should get focus again on re-entry with Tab. Use
the nomemory modifier to disable it. This is mainly used in combination with the
focusgroupstart attribute (see demo below).
Any modifier can be omitted if you only want to specify certain ones. By default, toolbar, tablist, and
menubar have the modifier inline, menu has the modifier block, and tablist, menu and
menubar have the modifier wrap.
Demo
toolbar wrap (horizontal navigation)
Click on a button to focus it and use the left and right arrow keys to navigate. When the first button is focused, you can use the left arrow to go to the last button, and when the last button is focused, you can use the right arrow to go to the first button.
toolbar nowrap (horizontal navigation)
Click on a button to focus it and use the left and right arrow keys to navigate. Since it has the nowrap
modifier, the navigation will stop at the first and last buttons and the focus will remain on that button when the
right or left arrow is pressed.
tablist with focusgroupstart (horizontal navigation)
Focus a button in the previous demo and use TAB to go to this demo. By default, the "Windows" button will be
focused when this demo is first entered with TAB because it has the focusgroupstart
attribute. Use the left and right arrow keys to navigate to another button and then use TAB to go to the next demo.
Use shift+TAB to go to the previous demo and notice that now the last focused button will get focus again instead
of the "Windows" button. So focusgroupstart only works when the focus group is first entered with TAB.
You can combine focusgroupstart with nomemory to always go back to the button with
focusgroupstart when returning to the focus group with TAB or shift+TAB (see demo below).
menubar and menu (horizontal and vertical navigation)
Use the left and right arrow keys to navigate the menubar and use Enter to open the submenu of each button. With a submenu open, use TAB to go to the submenu and then use the up and down arrow keys to navigate the submenu. Use ESC to close the submenu and return to the menubar.
menu (vertical navigation)
Use the up and down arrow keys to navigate the menu.
menu inline nomemory (horizontal navigation)
Focus a button in the previous demo and use TAB to go to this demo. By default, the "Bold" button will be
focused because it has the focusgroupstart attribute. Use the left and right arrow keys to navigate
to another button and then use TAB to go to the next demo.
Use shift+TAB to go to the previous demo and notice that the "Bold" button will get focus again instead
of the last focused button because it has the nomemory modifier.
toolbar wrap with focusgroup="none"
Elements with focusgroup can be nested and elements in the group can be excluded from arrow
navigation with focusgroup="none". Click the first button in the demo below and use the left and
right arrows to navigate between them, notice that the second button cannot be reached with arrow keys.
Documentation
Focusgroup on Chrome Developer BlogBrowser support
Focusgroup is supported in Chrome and Edge 146+ with Experimental Web Platform Features enabled or with an origin trial.