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

ARIA Attributes for Tab Components

Implementing aria-selected, aria-controls, and aria-labelledby to connect tabs with their panels.

ARIA Attributes for Tab Components

What you'll learn: How to use aria-selected, aria-controls, and aria-labelledby to create accessible connections between tabs and their content panels.

Why ARIA Attributes Matter for Tabs

You've already structured your tabs with semantic HTML. Now you need to tell assistive technologies which tab is active, which panel it controls, and how they relate to each other. Think of ARIA attributes as the "wiring" that connects the light switches (tabs) to the lights (panels).

The Three Essential Attributes

aria-selected indicates which tab is currently active. Set it to "true" on the active tab and "false" (or omit it) on inactive tabs. Screen readers announce "selected" when users land on the active tab.

<button role="tab" aria-selected="true">Profile</button>
<button role="tab" aria-selected="false">Settings</button>

aria-controls connects each tab to its corresponding panel using the panel's id. This tells screen readers, "this tab controls that panel over there."

<button role="tab" aria-controls="profile-panel">Profile</button>
<div role="tabpanel" id="profile-panel">...</div>

aria-labelledby works in the opposite direction—it connects each panel back to its tab. This provides context when a user navigates directly to the panel content.

<button role="tab" id="profile-tab">Profile</button>
<div role="tabpanel" aria-labelledby="profile-tab">...</div>

Putting It Together

Each tab needs a unique id, aria-selected status, and aria-controls pointing to its panel. Each panel needs a matching id and aria-labelledby pointing back to its tab. When users activate a tab, update aria-selected on both old and new tabs.

Key Takeaway: Use aria-selected to mark active tabs, aria-controls to link tabs to panels, and aria-labelledby to label panels with their tab names—creating a complete accessible relationship.