liveBook · Manning

Tab panel

As explained in Architecting Accessibility

A tab panel is the content region associated with and displayed by a tab in a tabbed interface.

A tab panel holds the content associated with a tab. Showing only the active panel—and hiding inactive panels—helps keep the interface clear for sighted users and assistive technology users. section 2.5.2

Give each panel a clear relationship to its tab:

  • Use role="tabpanel" and aria-labelledby to identify the panel and name it from its associated tab. section 2.5.2
  • Use aria-controls on the tab to point to the panel; set hidden on inactive panels. section 2.5.2
  • Set tabindex="0" on the active panel when its contents do not start with a naturally focusable element. 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 HTML example linking Overview and Technical Specifications tabs to their panels. section 2.5.2

ARIA attributes alone do not make tabs work: JavaScript must update the selected tab, show its panel, and manage keyboard focus. section 2.5.2

How Architecting Accessibility covers it

How deep it goes
Explains panel naming, visibility, and focus, and notes that JavaScript must coordinate selection, display, and keyboard focus.
Examples
Uses Overview and Technical Specifications panels in an HTML product-specifications tab interface.
What you can do after
Build an HTML tab interface that associates tabs with panels and updates their visibility and focus through JavaScript.
How it connects
Connects tab panels with tabs, ARIA attributes, keyboard focus, and JavaScript.

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.