In this video, you read the accessible names of the choir’s links, buttons and fields in DevTools, and saw the order the browser takes a name from.
Key Points
- When Tomás’s screen reader reaches a control, it tells him its role, what kind of control it is, and its accessible name, what it’s called. The footer’s icon-only Instagram link has an empty name, so the page gives him no words for where the link goes.
- To read a name, right-click an element and choose Inspect, then open the Accessibility tab in the Elements panel’s sidebar. Under Computed Properties, Name shows the name and Role shows the role.
- Expand Name to see every source the browser could take a name from, in the order it checks them. Sources it found nothing in say Not specified, and sources after the one it used are crossed out, because once the browser finds a name, it stops looking.
- The browser takes the first source in this order that has text:
aria-labelledby, which points at other text on the page by itsid. The choir’s site doesn’t use it.aria-label, a name written into an attribute. The narrow-screen Menu button’s only content is an icon markedaria-hidden, so its name, Menu, comes fromaria-label. The footer’s Instagram link is built the same way, minus thearia-label, which is why its name is empty.- The native label: a
<label>for a field, such as Your name on the sign-up form, or a<legend>for a group of checkboxes. - The content, for controls you press, such as links and buttons: they take their name from what’s inside them. Fields and plain text don’t. That’s where the Rehearsals link’s name comes from.
titleandplaceholder, as last resorts. The sign-up form’s email field has no label, so its name, Email, comes from its placeholder. That works, but it’s a last resort for a reason, and the next lesson shows why.- Fields don’t take their name from their content. The voice-part
<select>shows “Choose your voice part”, but with no label it has no name at all. The pane gives its role as combobox, its word for a select. - A paragraph, such as the hint under the email field, is text to read. It isn’t a control, so it needs no name, and its empty name is expected. Watch out: with their default roles, ARIA doesn’t allow a name on a plain paragraph,
<div>or<span>, so anaria-labelon one doesn’t name it. - When a name surprises you, the Accessibility pane shows which source it came from.
The Final Code
This video changes no code. These are the starting site’s elements whose names you read. First, the narrow-screen Menu button in the header: