liveBook · Manning

Roving tabindex

As explained in Architecting Accessibility

Roving tabindex is a keyboard-focus pattern in which only one element in a composite widget is included in the sequential focus order at a time.

For keyboard users, a tab list should not require a Tab-key stop on every tab. Roving tabindex keeps only the active tab in the normal Tab order; arrow keys move focus among tabs, and Tab moves on to the active panel. section 2.5.2

In a tabbed interface:

  • Give the active tab tabindex="0" and inactive tabs tabindex="-1". Inactive tabs are skipped by Tab but can still receive focus programmatically. section 2.5.2
  • Use JavaScript to update the selected tab, show its panel, hide inactive panels, and manage focus. section 2.5.2
  • When a panel needs to receive focus, such as when it has no naturally focusable content at the start, give it tabindex="0". section 2.5.2
Listing 2.2 Tabbed interface implemented in HTML, including ARIA attributes
...
<main>
  <section class="tabs">
    <!-- TABS -->
    <div role="tablist" #A
      aria-label="Product Specifications"
      id="specs-tabs">
        <button type="button" role="tab" #B
          aria-selected="true" #C
          aria-controls="panel-1" #D
          id="tab-1" 
          tabindex="0"> #E
            Overview
        </button>
        <button type="button" role="tab"
          aria-selected="false" 
          aria-controls="panel-2" 
          id="tab-2" 
          tabindex="-1"> #F
            Technical Specifications
        </button>
    </div>
    <!-- PANELS -->
    <div role="tabpanel" #G
      id="panel-1"
      tabindex="0" #H
      aria-labelledby="tab-1"> #I
        <p>
          This product is lovely, durable and designed for 
          something - not sure yet. Comes with a 25-year 
          all-in warranty.
        </p>
        <p>
          This is a <a href="#">focusable</a> element.
        </p>
        <img src="images/TabInterface.jpg" 
          alt="Close up of red object" 
          class="product_image" />
     </div>
     <div role="tabpanel" 
       id="panel-2" 
       tabindex="0"
       aria-labelledby="tab-2" 
       hidden> #J
         <ul>
           <li>Dimensions: 100 × 200 × 15mm</li>
           <li>Weight: 15Kg</li>
         </ul>
     </div>
   </section>
 </main> 
...

See the tablist, tab, and panel markup, including the active and inactive tabindex values. section 2.5.2

How Architecting Accessibility covers it

How deep it goes
Explains tabindex values, arrow-key movement, panel focus, and JavaScript updates to selection and visibility.
Examples
Uses a product-specifications tab list with Overview and Technical Specifications tabs and associated content panels.
What it assumes
Explains ARIA roles and tabindex values in the context of tabs while requiring custom JavaScript for dynamic behavior.
What you can do after
Build it from scratch by assigning tabindex values and using JavaScript to manage tab selection, panels, and keyboard focus.
How it connects
Connects tab widgets with ARIA roles, keyboard focus, and assistive technology.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting Accessibility. The section links point to the parts of the book it draws on.