A custom component can look right yet leave keyboard or screen-reader users unable to operate it. The WAI-ARIA Authoring Practices Guide (APG) is an example-driven reference for building components when native HTML does not provide the needed interaction. Its patterns describe ARIA semantics, expected keyboard behavior, focus management, and state management. section 2.5.2 section 6.1.9
Start with a native element where one fits. ARIA describes a custom component; it does not supply its behavior or repair a broken interaction. CSS can often meet design requirements while preserving native controls. When an interaction genuinely needs a custom component, use an APG pattern as a starting point—not as a ready-made component library. section 2.5.2 section 6.1.9
When using a pattern:
- Check its roles and attributes alongside its keyboard, focus, and state requirements. section 2.5.2 section 6.1.9
- Test the result with a keyboard and screen reader. For third-party components, check accessibility documentation and test behavior rather than trusting the presence of ARIA attributes. section 2.5.2
Tabbed interface
A tabbed interface pairs tab buttons with content panels. The HTML identifies the tab list, tabs, and panels; JavaScript handles keyboard movement, selection, focus, and which panel is shown. ARIA attributes alone cannot make those interactions work. 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>
...
Inspect the tab-list, tab, and tab-panel roles and the attributes linking tabs to their panels. section 2.5.2
function onTabKeyDown(event, mode) {
const currentIndex = tabs.indexOf(document.activeElement);
if (currentIndex === -1) return;
const { key } = event;
if (mode === 'manual' && (key === 'Enter' || key === ' ')) { #A
event.preventDefault(); #B
setActiveTab(currentIndex, { setFocus: true });
return;
}
const nextIndex = getNextTabIndex(key, currentIndex, tabs.length); #C
if (nextIndex === undefined) return;
event.preventDefault();
tabs[nextIndex].focus({ preventScroll: true }); #D
if (mode === 'auto') {
setActiveTab(nextIndex, { setFocus: false }); #E
}
}
function getNextTabIndex(key, current, total) {
switch (key) { #F
case 'Home':
return 0;
case 'End':
return total - 1;
case 'ArrowRight':
return (current + 1) % total; #G
case 'ArrowLeft':
return (current - 1 + total) % total; #H
default:
return undefined;
}
}
Inspect how arrow, Home, and End keys move focus, and how manual and automatic activation differ. section 2.5.2
