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

Semantic HTML Structure for Tabs

Building the foundation with proper HTML elements including tablist, tab, and tabpanel roles.

Semantic HTML Structure for Tabs

You'll learn how to build an accessible tabs component using the proper HTML elements and ARIA roles that screen readers and assistive technologies understand.

Why Structure Matters

Think of tabs like labeled dividers in a filing cabinet—each tab shows a label, and clicking it reveals its corresponding content panel. For this to work accessibly, browsers and screen readers need to understand three distinct pieces: the overall tabs container, each individual tab, and each content panel.

The Three Key Roles

When building tabs, you need to mark up your HTML with these ARIA roles:

tablist – This wraps all your tab buttons together, telling assistive technology "here's a group of tabs." It's like the strip at the top holding all the folder labels.

tab – Each clickable tab button gets this role. These are typically <button> elements that control which panel is visible.

tabpanel – The content area associated with each tab. When a tab is selected, its corresponding panel becomes visible.

Basic Structure Example

<div role="tablist" aria-label="Account Settings">
  <button role="tab" aria-selected="true" aria-controls="profile-panel">
    Profile
  </button>
  <button role="tab" aria-selected="false" aria-controls="security-panel">
    Security
  </button>
</div>

<div role="tabpanel" id="profile-panel">
  Profile settings content...
</div>

<div role="tabpanel" id="security-panel" hidden>
  Security settings content...
</div>

Notice how aria-controls connects each tab to its panel using IDs, and aria-selected indicates which tab is currently active.

Key Takeaway: Accessible tabs require three semantic pieces—a tablist container, individual tab buttons, and tabpanel content areas—all connected through ARIA attributes so assistive technologies can announce relationships and states.