Skiplink

Guides

Accessible names for icon buttons and links (button-name, link-name)

A magnifying glass, a cross, a basket. Sighted users read the icon; a screen reader reads the accessible name, and on an icon-only control there often is not one. It is one of the easiest violations to fix.

What the rules check

Every interactive element needs an accessible name: the text a screen reader announces and a voice-control user says to activate it. For buttons and links the name usually comes from the text inside them. Remove the text and put an icon there instead, and the name is gone.

Two axe-core rules catch this:

Related rules cover the same problem on other elements: input-button-name for <input type="button"> and friends, aria-command-name for elements given role="button" or role="link".

What fails

<!-- Icon font: no text at all -->
<button class="btn-icon"><i class="icon-search"></i></button>

<!-- Inline SVG with no title or label -->
<a href="https://example.com/cart">
  <svg viewBox="0 0 24 24"><path d="…"/></svg>
</a>

<!-- An image whose alt is empty, so it contributes nothing -->
<button><img src="https://cdn.example.com/close.svg" alt=""></button>

To a screen reader the first is announced as just "button", the second as a link with no name (often read out as its URL), and the third as "button" again.

Four ways to fix it

1. Visually hidden text. The most robust option: the name is real text in the DOM, it is translated along with the rest of the page, and every assistive technology reads it.

<button class="btn-icon">
  <svg aria-hidden="true" focusable="false" viewBox="0 0 24 24"><path d="…"/></svg>
  <span class="visually-hidden">Search</span>
</button>
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

Do not use display: none or hidden for this; they remove the text from the accessibility tree as well as from the screen.

2. aria-label. Shorter, and fine for a single word. It is easy to forget when the page is translated, because automatic translation usually ignores attributes.

<a href="https://example.com/cart" aria-label="Basket">
  <svg aria-hidden="true" focusable="false" viewBox="0 0 24 24"><path d="…"/></svg>
</a>

3. aria-labelledby. Points at text that already exists elsewhere in the page, such as the tooltip an editor toolbar shows on hover.

<button aria-labelledby="tip-bold">
  <svg aria-hidden="true" focusable="false" viewBox="0 0 24 24"><path d="…"/></svg>
</button>
<div role="tooltip" id="tip-bold" hidden>Bold</div>

aria-labelledby may point at hidden text, one of the few places where hidden content still counts, so the button is named "Bold" whether or not the tooltip is showing.

4. Alt text on an image inside the control. If the icon is an <img>, its alt is the name.

<button><img src="https://cdn.example.com/close.svg" alt="Close"></button>

In each case the aria-hidden="true" on the SVG keeps the graphic itself from being announced, and focusable="false" stops older browsers giving the SVG its own tab stop.

A title attribute on its own also satisfies the rules, but it shows only on mouse hover, not on touch or keyboard focus, and is announced inconsistently. Treat it as a tooltip, not a name.

Choosing the words

Name the action or the destination, not the picture. "Search", not "Magnifying glass". "Close", not "X". "Basket, 3 items", not "Cart icon". If two icon buttons on the same page do different things, they need different names; three buttons all called "Edit" in a list of addresses should say which address.

If a control has visible text and you add an aria-label as well, the label replaces the visible text as the name. Keep the visible words at the start of the label. A button that says "Send" on screen and is named "Submit message" in code fails 2.5.3 Label in Name (opens in a new tab), and a voice-control user saying "click Send" gets nothing.

What a scanner cannot tell you

button-name and link-name check that a name exists. They cannot check that it is any good. All of these pass:

<button aria-label="button"><svg aria-hidden="true">…</svg></button>
<a href="https://example.com/cart" aria-label="icon"><svg aria-hidden="true">…</svg></a>
<a href="https://example.com/report.pdf">Click here</a>

Whether "Click here" makes sense depends on the surrounding sentence, which is what 2.4.4 means by "in context", and that is a judgement a person makes. Neither will a scanner notice that two controls with different jobs share a name, or that a name is in the wrong language. A quick manual pass with a screen reader's list of buttons and links catches most of these in a few minutes.

Keeping them fixed

Icon-only controls are added constantly, often by copying an existing one, so these rules are good candidates for a CI gate that fails on new violations. The criteria table lists every rule mapped to 4.1.2, and what a scan does not tell you covers the judgements no rule makes.

Try it on your own site: scan a URL for free, or read the docs to add a baseline to your pipeline.