How accessible is your website?Start free check
Guides

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

Clara BailyPublished 3 min read

Blog cover with the title aria-label in HTML and a line drawing of stacked frames

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 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, 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.

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.

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.

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.

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
  • 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
  • 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. If a button shows "Send", its accessible name has to contain "Send".

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.

When should I use aria-label?

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.

What is the difference between aria-label and aria-labelledby?

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.

Does aria-label work on a div?

Not reliably. On elements without a suitable role, screen readers often ignore it. Use a button, link or element with a proper role.

Is aria-label read by screen readers?

Yes. On supported elements it replaces the visible content as the accessible name.

Share this article

Sources

  1. MDN: aria-label
  2. W3C: Understanding Success Criterion 4.1.2 Name, Role, Value
  3. W3C: Understanding Success Criterion 2.5.3 Label in Name
  4. W3C: Using ARIA

About the author

Clara Baily

Accessibility specialist

Clara Baily has been on the allyWay team from the start. She has looked after every accessibility product the team has built, including OneTap, which runs on more than 80,000 websites, AltPilot and the internal accessibility checker. She writes about WCAG, accessibility laws and fixes that work on real websites.

Let AI Handle Website Accessibility

Built in Europe. Set up in 2 minutes, no developer needed. Put website accessibility on autopilot with AI-powered fixes and automated monitoring.

  1. 1Choose your plan
  2. 2Install in 2 min
  3. 3AI fixes your website
  4. Done