Skip to content
easeweb
Search topics

Tabs that only work with a mouse

Product tabs are list items with click handlers, so they take no keyboard focus and say nothing about which panel is shown.

WCAG 2.2
SC 4.1.2ASC 2.1.1A
Required by
Section 508 · EN 301 549 (EU)
Broken <li class="tab active" onclick="show('description')">
The accessibility problem illustrated: Motor:How do I get to Sizes?
01

The problem

Keyboard users can't open any tab but the first, and screen reader users aren't told that the tabs switch content or which one is shown

02

Try it

Open the Sizes tab with the keyboard

Press Tab, then try the arrow keys, Home and End. The panel shows what a screen reader says. Does it say which tab is shown?

Broken Can you fix this?

BrokenList items with click handlers
  • Description
  • Sizes
  • Reviews (12)

Waxed cotton, lined with wool. Care instructions

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Make the tabs work by keyboard, and say which is shown

Before
BrokenList items with click handlers
<ul class="tabs">  <li class="tab active" onclick="show('description')">Description</li>  <li class="tab" onclick="show('sizes')">Sizes</li>  <li class="tab" onclick="show('reviews')">Reviews (12)</li></ul><div class="panel" id="description">  <p>Waxed cotton, lined with wool. <a href="/care">Care instructions</a></p></div><div class="panel" id="sizes" style="display: none">…</div><div class="panel" id="reviews" style="display: none">…</div>
What is wrong3 points
  • A keyboard user can't open Sizes or Reviews. The tabs are li elements with click handlers, which are never in the Tab order.
  • A screen reader user isn't told that these words are tabs, or that they control the panels below. Nothing in the code says so.
  • Only someone who can see the page can tell which tab is selected. The active class shows it to the eye only.
After
FixThe tabs pattern on buttons
<div role="tablist" aria-label="Product details">  <button type="button" role="tab" id="tab-description"          aria-selected="true" aria-controls="panel-description">Description</button>  <button type="button" role="tab" id="tab-sizes"          aria-selected="false" aria-controls="panel-sizes" tabindex="-1">Sizes</button>  <button type="button" role="tab" id="tab-reviews"          aria-selected="false" aria-controls="panel-reviews" tabindex="-1">Reviews (12)</button></div><div role="tabpanel" id="panel-description" aria-labelledby="tab-description" tabindex="0">  <p>Waxed cotton, lined with wool. <a href="/care">Care instructions</a></p></div><div role="tabpanel" id="panel-sizes" aria-labelledby="tab-sizes" tabindex="0" hidden>…</div><div role="tabpanel" id="panel-reviews" aria-labelledby="tab-reviews" tabindex="0" hidden>…</div>
How it is fixed6 steps
  1. Make each tab a button with role="tab", inside a role="tablist" named "Product details", and point each one's aria-controls at its panel.
  2. Mark the shown tab with aria-selected="true" and give the others tabindex="-1". The tab list takes one Tab stop, on the selected tab, and a screen reader announces something like "Sizes, tab, selected, 2 of 3".
  3. Handle the arrow keys, Home and End. The arrows move between tabs and show each one's panel as they go; Home and End jump to the ends.
  4. Keep every panel in the page as a tabpanel, and hide all but the shown one with hidden. aria-controls always points at a real element, and the links in hidden panels take no focus.
  5. Give the panels tabindex="0", because they start with text, so the next Tab after the tab list lands on the panel itself.
  6. Draw the selected look from aria-selected, so it can't show one tab while the code marks another.

This fixes the Before and passes 2.1.1 and 4.1.2.

04

Design ideas

The selected tab can be drawn many ways

Four ways to draw the jacket page’s tabs. Click a tab, or Tab to the row and use the arrow keys. Two mark the selected tab with a shape at 3:1 or more, not by colour alone; two look calm until you have to tell which tab is shown.

In the design file

  • Mark the selected tab with a shape, not just colour, such as a 3-pixel bar, a border or bold text, at 3:1 contrast or more.
  • Draw a tab with focus, looking different from the selected tab.
  • Draw the tabs in a Windows contrast theme, where the selected tab still shows by a line or bold text, not its background.
  • Draw what the tabs become on a phone, still a row or sections that open one at a time, and say which.

Passes

  • Waxed cotton, lined with wool.

    A white chip on a tinted track The selected tab is a raised white chip on a pale #eef3f0 track, with a 1px #2d6a4f edge, 5.69:1 against the track, and semibold words. White against the track is only 1.12:1, so the edge and the weight carry it; the shadow alone would not.
  • Waxed cotton, lined with wool.

    A tab joined to its panel The other tabs sit on a pale #eef3f0 fill. The selected one turns white inside a 1px #767676 edge, 4.54:1 on white, and the panel’s border opens under it, so tab and panel read as one sheet. The edge and the open border say which tab is shown, not the fill: white against #eef3f0 is only 1.12:1.

Fails

  • Waxed cotton, lined with wool.

    The selected tab only in the brand colourWCAG 1.4.1 The selected tab is #2d6a4f green and the others #555555 grey, in the same weight with no bar. Each passes as text, 6.39:1 and 7.46:1, but the two are only 1.17:1 apart, so to someone who can’t tell green from grey the three words look the same.
  • Waxed cotton, lined with wool.

    A pale hairline under the selected tabWCAG 1.4.11 All three tabs are the same #1a1a1a words; only a 1px #c5d3c9 line marks the selected one, 1.55:1 against the page. It looks refined in a mock-up, but the line is the only thing that shows which tab is selected, so it needs 3:1.
05

Verify the fix

5 checks, no mouse.

Test with: Keyboard, Screen reader, Zoom, Forced colors

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared tabs component changes.

Limits

This is a starting pattern, not a guarantee for every application. The script is a minimal sketch: it handles one tab list per page, and has no deep links or remembered selection. Screen readers word tabs and their position differently. Test the complete journey with your target assistive technology.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service