Testing aria-label
Which of the examples below correctly use aria-label?
Example 1: Valid use on a button
Accessible name for the <button> should be: Close dialog
HTML markup
<button aria-label="Close dialog">✕</button>
Example 2: Valid use on a landmark
Accessible name for the <nav> should be: Primary navigation
HTML markup
<nav aria-label="Primary navigation">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
Example 3: Valid use on an input
Accessible name for the <input> should be: Search this site
HTML markup
<input type="search" aria-label="Search this site">
Example 4: Empty aria-label
Accessible name for the <button> should be: Submit
. The empty aria-label will be ignored.
HTML markup
<button aria-label="">Submit</button>
Example 5: Whitespace-only aria-label
Accessible name for the <button> should be: Submit
. The aria-label containing only whitespace will be ignored.
HTML markup
<button aria-label=" ">Submit</button>
Example 6: Prohibited role — <p>
This paragraph has an aria-label.
There will be no accessible name for the <p> as this role does not allow naming.
HTML markup
<p aria-label="Important notice">This paragraph has an aria-label.</p>
Example 7: Prohibited role — <span>
This span has an aria-label.
There will be no accessible name for the <span> as this role does not allow naming.
HTML markup
<span aria-label="Hello world">This span has an aria-label.</span>
Example 8: Prohibited role — role="none"
This element has a role of none.
There will be no accessible name for the <div> as this role does not allow naming.
HTML markup
<div role="none" aria-label="Hello world">This element
has a role of none.</div>