Dostępność

a11y/control-name

Every button and link has an accessible name; icon-only controls get visually hidden text or aria-label.

krytycznastatyczneWCAG 4.1.2, 2.4.4 · Afe-a11y-aria

Dlaczego

A button with only an icon is announced as "button" and nothing else. Screen reader and voice control users cannot tell what it does or say its name to activate it.

Poprawka

Prefer visible text. For an icon-only control, add text that is hidden visually but read (<span class="sr-only">Close</span>) or aria-label="Close", and mark the icon aria-hidden="true". A linked image names the link through its alt. Use the same word people see in tooltips and elsewhere on the site.

Przykłady

<!-- bad -->
<button type="button"><svg aria-hidden="true">…</svg></button>
<!-- good -->
<button type="button" aria-label="Close"><svg aria-hidden="true">…</svg></button>
<button type="button"><svg aria-hidden="true">…</svg><span class="sr-only">Close</span></button>

Źródła

Fakty

Identyfikator
a11y/control-name
Waga
krytyczna
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
html angular vue svelte astro jsx
WCAG 2.2
4.1.2, 2.4.4, poziom A
Ten sam problem w
axe-core button-name, axe-core link-name, axe-core input-button-name, Lighthouse button-name, Lighthouse link-name
Uczy jej skill
fe-a11y-aria ARIA, names and live regions
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain a11y/control-name