What is aria-label?

aria-label gives an element an accessible name as a string, which screen readers announce instead of (or in the absence of) visible text. Use it when an interactive element has no visible text label, such as an icon-only button, a search field without a visible label, or a second <nav> that needs distinguishing.

How accessible names are chosen (simplified priority)

  1. aria-labelledby (references other elements' text)
  2. aria-label
  3. Native labeling: <label for>, alt, <caption>, <legend>, or the element's own text content
  4. title (last resort)

So aria-label overrides the visible text of a button, which can confuse voice-control users if the two differ.

Good uses

  • <button aria-label="Close dialog">✕</button>
  • <nav aria-label="Breadcrumb"> and <nav aria-label="Primary"> to tell landmarks apart.
  • <input type="search" aria-label="Search products"> when the design has no visible label (a visible <label> is still better).

Pitfalls

  • Prefer visible text. Labels help everyone, not just screen reader users.
  • If visible text exists, the accessible name should contain it (WCAG 2.5.3 Label in Name): visible "Buy" should not be labeled "Purchase item".
  • It does not work reliably on non-interactive elements without a role, like a plain <div> or <span>.
  • It is not translated by some auto-translation tools.
  • Use aria-labelledby when the label already exists on screen, and aria-describedby for extra hints.

Code example

html
1<style>
2 body { font-family: system-ui; }
3 .icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 2px solid #0b1020; font-size: 18px; }
4</style>
5
6<nav aria-label="Primary"><a href="#">Home</a> · <a href="#">Docs</a></nav>
7<nav aria-label="Breadcrumb"><a href="#">Docs</a> › <span aria-current="page">ARIA</span></nav>
8
9<!-- Icon-only buttons need an accessible name -->
10<button class="icon-btn" aria-label="Close dialog">✕</button>
11<button class="icon-btn" aria-label="Add to favorites">♥</button>
12
13<!-- Prefer aria-labelledby when the label is already visible -->
14<h2 id="billing">Billing address</h2>
15<section aria-labelledby="billing">
16 <input type="search" aria-label="Search addresses">
17</section>
18
19<script>
20 // The accessibility tree uses the aria-label, not the "✕" glyph
21 for (const b of document.querySelectorAll(".icon-btn")) {
22 console.log(b.textContent, "->", b.getAttribute("aria-label"));
23 }
24</script>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.

Open in study app