# aria-label in HTML: 8 examples for buttons, links and icons

Source: https://allyway.ai/blog/aria-label-html

Author: Clara Baily · Published: 2026-11-10

aria-label gives an element an accessible name when no visible text exists. 8 copy-ready HTML examples for icon buttons, links and fields, plus 4 mistakes.

## Key takeaways

- aria-label gives an element an accessible name that screen readers announce, when there's no visible text to use.
- It belongs on interactive elements such as buttons, links and form fields, and on landmarks.
- Visible text beats aria-label. If text is on screen, use it or reference it with aria-labelledby.
- The accessible name should contain the visible label, so voice control users can say what they see.

Use `aria-label` when an element has no visible text that names it, like an icon button: `<button aria-label="Close">×</button>`. Screen readers announce "Close, button" instead of "times" or nothing at all.

That's the core idea. Below are eight examples you can copy, four mistakes to avoid and the one rule that tells you when `aria-label` is the right tool.

## The rule first

`aria-label` sets the accessible name of an element. Use it only when there's no visible text you could use instead. If the text is on screen, use the text itself, or point to it with `aria-labelledby`. The W3C's [Using ARIA](https://www.w3.org/TR/using-aria/) guidance puts it plainly: a native HTML element with visible text beats an ARIA attribute.

Missing names on buttons and links fail [WCAG 4.1.2 Name, Role, Value](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html), one of the most frequent failures in accessibility scans.

## 8 examples

### 1. Icon-only close button

```html
<button type="button" aria-label="Close dialog">
  <svg aria-hidden="true" focusable="false">...</svg>
</button>
```

The SVG is hidden from screen readers with `aria-hidden="true"`, and the button carries the name.

### 2. Hamburger menu button

```html
<button type="button" aria-label="Menu" aria-expanded="false" aria-controls="main-nav">
  <span class="icon-burger" aria-hidden="true"></span>
</button>
```

`aria-expanded` tells users whether the menu is open. Your script switches it to `true` when the menu opens.

### 3. Social media icon links

```html
<a href="https://www.linkedin.com/company/example" aria-label="allyWay on LinkedIn">
  <svg aria-hidden="true" focusable="false">...</svg>
</a>
```

Name the destination, not the icon. "LinkedIn icon" tells nobody where the link goes.

### 4. Search field without a visible label

```html
<form role="search">
  <input type="search" name="q" aria-label="Search products">
  <button type="submit">Search</button>
</form>
```

A visible label is better for everyone. If the design really has none, `aria-label` gives the field a name.

**How accessible is your website? Check your site for free in 10 seconds.**

A free scan against WCAG 2.2 AA shows every issue on your page.

[Check for free](https://allyway.ai/free-wcag-accessibility-scanner-for-websites)

### 5. Two navigation areas

```html
<nav aria-label="Main">...</nav>
<nav aria-label="Footer">...</nav>
```

When a page has more than one `nav`, labels let screen reader users tell them apart in the landmarks list.

### 6. Pagination links

```html
<nav aria-label="Pagination">
  <a href="?page=2" aria-label="Page 2">2</a>
  <a href="?page=3" aria-label="Page 3" aria-current="page">3</a>
</nav>
```

A bare "2" is ambiguous out of context. Note that the visible number stays part of the name.

### 7. Shopping cart button with a count

```html
<a href="/cart" aria-label="Cart, 3 items">
  <svg aria-hidden="true" focusable="false">...</svg>
  <span aria-hidden="true">3</span>
</a>
```

The name carries the count, and the visual badge is hidden so it isn't read twice.

### 8. Repeated "Read more" links

```html
<a href="/blog/wcag-2-2" aria-label="Read more about WCAG 2.2">Read more</a>
```

Better still: write descriptive link text that everyone sees. If the design insists on "Read more", the label keeps the visible words at the start.

## 4 mistakes to avoid

**Do:** Do

- Put aria-label on buttons, links, form fields and landmarks.
- Keep the visible text inside the name, at the start.
- Write short names that describe the action or destination.
- Prefer visible text or aria-labelledby when text exists.

**Don't:** Don't

- Put aria-label on a div or span without a role. Screen readers often ignore it there.
- Contradict the visible text. Voice control users say what they see, and it has to match.
- Label decorative icons. Hide them with aria-hidden instead.
- Add "button" or "link" to the name. The role is announced already.

The second point is a WCAG rule of its own: [2.5.3 Label in Name](https://www.w3.org/WAI/WCAG22/Understanding/label-in-name.html). If a button shows "Send", its accessible name has to contain "Send".

## How allyWay solves missing button and link names

allyWay finds every button, link and form field without an accessible name and fixes it automatically with AI, directly on your live site. You add one line of code or install the plugin, and allyWay is live in about 2 minutes.

Every new page is checked continuously, so unnamed icon buttons from a new plugin or theme update don't stay unnoticed. You see every change in the dashboard. Agencies run it under their own brand.

Q: When should I use aria-label?
A: When an interactive element or landmark has no visible text that could serve as its name, such as an icon button or a second navigation area.

Q: What is the difference between aria-label and aria-labelledby?
A: aria-label holds the name as a string. aria-labelledby points to the ID of visible text on the page that should be used as the name.

Q: Does aria-label work on a div?
A: Not reliably. On elements without a suitable role, screen readers often ignore it. Use a button, link or element with a proper role.

Q: Is aria-label read by screen readers?
A: Yes. On supported elements it replaces the visible content as the accessible name.

**Make your website accessible. Live in 2 minutes, AI does the rest.**

Live in 2 minutes. allyWay finds and fixes issues and checks every new page.

[Start for free](https://app.allyway.ai/register)

## Sources

- [MDN: aria-label](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label)
- [W3C: Understanding Success Criterion 4.1.2 Name, Role, Value](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html)
- [W3C: Understanding Success Criterion 2.5.3 Label in Name](https://www.w3.org/WAI/WCAG22/Understanding/label-in-name.html)
- [W3C: Using ARIA](https://www.w3.org/TR/using-aria/)
