Skip to content

A control inside another control

a11y-nested-interactiveserious
On this page

Why it matters

  • A button tells a screen reader its name and nothing of what is inside it. A link placed inside a button is not announced, and the keyboard may stop on it, or not, depending on the browser.
  • Which of the two a click or a tap triggers then depends on where it lands, and people who cannot see it cannot tell.
  • WCAG 2.2 asks that every control expose its name and role correctly (success criterion 4.1.2, level A).

Example

Wrong
<div id="offer" role="button" tabindex="0">أضف إلى السلة <a href="#details" style="display:inline-block;line-height:24px">تفاصيل العرض</a></div>
Right
<button id="offer" type="button">أضف إلى السلة</button> <a href="#details">تفاصيل العرض</a>

How to fix

Put the two controls side by side:

html
<button id="offer" type="button">أضف إلى السلة</button> <a href="#details">تفاصيل العرض</a>
  • If the whole card should be clickable, make one link of it and keep buttons out of it.

How we detect

  1. We render the page and run axe-core 4.13.0's nested-interactive rule in each engine.
  2. It reports an element whose role keeps its content out of the accessibility tree (a button, a tab, a checkbox and the like) when something inside it can take focus.