Lesson 1 of 8

Tabs

Goal

A component screen readers understand

01

Explanation

Tabs aren't just buttons that hide some elements and show others. They have standard roles that you need to add: role="tablist" on the container, role="tab" with aria-selected on each tab, and role="tabpanel" on each content panel.

With these roles, a screen reader knows it's looking at tabs, how many there are and which one is open right now, even though it can't see the page.

Hide the panels with the hidden attribute instead of a CSS class that sets display:none. The state then lives in the HTML itself, and hidden takes the panel out of the accessibility tree as well as off the screen.

02

Your task

Make clicking any tab switch the selected tab and the visible panel together, and update aria-selected.

Checks

6 checks
  1. The first tab is selected and its panel is visible
  2. Clicking the second tab moves the selection to it
  3. The second tab's panel shows instead of the first
  4. Only one tab is selected at a time
  5. Only one panel is visible
  6. Going back to the first tab works
03

Hints

0/3
Track lessons0 of 8 done

Build from scratch, on your own, the components you'll find on almost every website, such as tabs, dialogs, tables, toasts and a carousel.

Advanced level, 8 lessons, 2 hours in total.

index.html
Preview
index.html100%
–/6

Press “Run and check” to grade your code.

6 checks listed under “Your task”.

Track lessons0 of 8 done

Build from scratch, on your own, the components you'll find on almost every website, such as tabs, dialogs, tables, toasts and a carousel.

Advanced level, 8 lessons, 2 hours in total.