Skip to content

Accessible Tab Component

Medium ~45 min

What you'll build

A tab component with 3-4 panels where users can switch tabs via mouse, keyboard (arrow keys, Home, End), and screen readers announce the current tab.

Goals

  • Implement the WAI-ARIA tabs pattern correctly
  • Support keyboard navigation (Arrow Left/Right, Home, End)
  • Manage focus and aria-selected/aria-hidden states
  • Make it reusable for any number of tabs

Prerequisites

  • HTML structure
  • CSS for styling active/inactive tabs
  • JavaScript keyboard event handling
  • Basic ARIA attributes

Steps

  1. 1

    Study the ARIA tabs pattern

    Read the WAI-ARIA Authoring Practices for tabs. Acceptance: the tablist has role='tablist', each tab has role='tab' and aria-controls, each panel has role='tabpanel' and aria-labelledby. Document the required attributes before coding.

  2. 2

    Build the HTML structure

    Create a tablist with N tabs and N corresponding panels. Wire aria-controls (tab→panel) and aria-labelledby (panel→tab). Only the active panel is visible initially.

  3. 3

    Implement click activation

    Clicking a tab activates it: set aria-selected=true on the clicked tab and false on others, show the corresponding panel and hide the rest. Acceptance: only one tab is selected at a time.

  4. 4

    Add keyboard navigation

    Arrow Right/Down moves focus to the next tab, Arrow Left/Up to the previous, Home to the first, End to the last. When focus moves, the newly focused tab becomes active. Acceptance: all keys work and no tab is skipped.

  5. 5

    Test with a screen reader

    Run NVDA or VoiceOver and navigate the tabs. Acceptance: the screen reader announces 'tab, X of N, selected' for the active tab and lets you switch with arrows. Verify focus is visible.

Try it yourself

What you learned

You built a component to WAI-ARIA standards — accessible tab components are a common interview task and a real test of whether you can make interactive UIs work for keyboard and screen reader users.

Related Resources

Related Lessons

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to topic