Course contentsShow
← Web Development
Lesson 1203 of 2,98221. Accessible ComponentsFree lesson

Toolbar Pattern

Create accessible toolbars with grouped controls and roving tabindex for efficient keyboard navigation.

Toolbar Pattern

What you'll learn: You'll learn how to build accessible toolbar interfaces that group related controls and allow smooth keyboard navigation without excessive tabbing.

What is a Toolbar?

A toolbar is a container that groups related controls—like formatting buttons, tools, or actions—into a single keyboard-navigable unit. Think of it like the ribbon in Microsoft Word or the formatting bar in a text editor. Without proper accessibility, users would need to tab through every single button individually, which becomes tedious when there are many controls.

The Core Pattern

The toolbar pattern uses grouped controls and roving tabindex to solve this problem:

  1. Group semantically using role="toolbar" on the container
  2. Make one control tabbable with tabindex="0", all others get tabindex="-1"
  3. Use arrow keys (← →) to move between toolbar items
  4. Tab key moves users past the entire toolbar as a single stop

When a user presses an arrow key, you programmatically:

  • Remove tabindex from the current control
  • Set focus and tabindex on the next/previous control
  • Update which button is the "active" one

Why This Matters

Without roving tabindex, a toolbar with 20 buttons requires 20 tab presses to navigate through. With it, the toolbar becomes a single tab stop, and arrow keys navigate within. This dramatically improves efficiency for keyboard-only users.

The toolbar acts like a single "widget" in the page's tab order, similar to how a native <select> element behaves—you tab to it once, then use arrows inside.

Example Attributes

<div role="toolbar" aria-label="Text formatting">
  <button tabindex="0">Bold</button>
  <button tabindex="-1">Italic</button>
  <button tabindex="-1">Underline</button>
</div>

Key Takeaway: The toolbar pattern groups related controls with role="toolbar" and uses roving tabindex (one tabindex="0", others -1) plus arrow key navigation to create a single, efficient keyboard stop.