References

Beginner-friendly references for web development, with live, editable examples.

The HTML aria-label attribute

ARIA Accessibility
In short

The aria-label attribute gives an element an accessible name from a string, as in <button aria-label="Close">. On a button or link, that string replaces the text inside as the name without appearing on screen. If the label text is already on the page, use aria-labelledby instead.

Overview

The aria-label attribute sets an element's accessible name, the short label assistive technology presents, from a string. A common case is a <button> that holds an SVG icon and no text. The attribute shows no tooltip and no text of its own.

The accessible name computation reaches the string before an element's <label>, alt text, own content or title. The one naming attribute ranked above it is aria-labelledby. On a <nav>, <section> or <table>, the string names the element and its content stays available.

WAI-ARIA 1.2 prohibits the attribute on the caption, code, deletion, emphasis, generic, insertion, paragraph, presentation (also called none), strong, subscript and superscript roles. The WAI-ARIA 1.3 Working Draft adds definition, mark, suggestion, term, time and tooltip.

The bans reach HTML elements through their roles, so authors must not use the attribute on a plain <div>, <span> or <p>, or on <code>, <strong> and <time>, among others. An explicit role that allows naming lifts the ban, as in <div role="group" aria-label="Filters">.

A prohibited aria-label has no dependable result. Chrome and Firefox still expose the text on a plain div, though the draft AccName 1.2 computation returns an empty string there. In practice, assistive technology supports it only on interactive elements, widgets, landmarks, images and iframes.

Syntax

<button aria-label="Close dialog">
  <svg aria-hidden="true" width="16" height="16"></svg>
</button>
<nav aria-label="Footer links">...</nav>

Values

Value
A string (the accessible name).

Example

Live example
<p>Click the speaker, then read the name it carries now.</p>
<button id="mute" type="button" aria-label="Mute" style="padding: 8px; line-height: 0;">
  <svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
    <path d="M4 9v6h4l5 4V5L8 9z"/>
    <path id="waves" d="M16 9a4 4 0 0 1 0 6"/>
  </svg>
</button>
<p role="status" id="out">aria-label is Mute. The button shows no text.</p>
<script>
const button = document.getElementById('mute');
const waves = document.getElementById('waves');
const out = document.getElementById('out');
button.addEventListener('click', function () {
  const muted = button.getAttribute('aria-label') === 'Mute';
  button.setAttribute('aria-label', muted ? 'Unmute' : 'Mute');
  waves.setAttribute('stroke', muted ? 'none' : 'currentColor');
  out.textContent = 'aria-label is ' + button.getAttribute('aria-label') + '. The button shows no text.';
});
</script>

Best practices

  • Write aria-label as a short name without the role word, so a button reads Close, not Close button.
  • Include a control's visible words in the string, ideally at its start, so the name contains the text people see.
  • Try the native feature first. A <label> on an <input>, alt on an <img> or title on an <iframe> makes this attribute unnecessary.
  • Keep instructions out of the name, and put them in visible text tied in with aria-describedby, or in the draft aria-description attribute.
  • Give each <nav> on a page its own string, such as Main and Footer, unless two hold identical content.
  • Update the string when the action changes. Script can use setAttribute or the ariaLabel property, supported since Chrome 81, Edge 81, Firefox 119 and Safari 12.1.

Frequently asked questions

Which elements need aria-label?
Use aria-label when an element needs a name and no text on the page can provide one. Its intended targets include links, videos, form controls, and elements with landmark or widget roles.
Should you use aria-label or aria-labelledby?
Choose aria-labelledby when the label text is in the DOM, and aria-label when it isn't. When both are set, aria-labelledby takes precedence unless its references are empty, a case the AccName 1.2 draft settles in aria-label's favor.
Does aria-label override an element's visible text?
Yes, aria-label replaces the visible text as the accessible name, and that text stays on screen. A link that shows Read more is named Read more about pricing when aria-label holds that string.
Can you put aria-label on a div?
A plain div isn't allowed aria-label, because its generic role prohibits naming. Add a role that allows a name, such as group or region.
How is aria-label different from the title attribute?
The aria-label attribute shows nothing, while title could present a browser tooltip. With both set, Chrome and Firefox use aria-label as the name and title as the description.
What happens when aria-label is empty?
An empty or whitespace-only aria-label is skipped by the name computation. The element falls back to its next source, so a button with the text Save stays named Save.
Does an aria-label on a child element count toward the parent's name?
Yes, a child's aria-label feeds a parent named from its content. A text field, select or range child adds its value instead, while a checkbox, radio button or button child keeps its aria-label.