Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Find an Element's Accessible Name

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 its id. 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 marked aria-hidden, so its name, Menu, comes from aria-label. The footer’s Instagram link is built the same way, minus the aria-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.
  • title and placeholder, 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 an aria-label on 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:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Tomás uses a screen reader. When he reaches a link or a button, it tells him what kind of control it is and what it’s called. That name is the element’s accessible name.

00:11 On the home page, the footer’s Instagram link is only an icon. Its name is empty, so the page gives Tomás no words for where the link goes. Before you fix names like this one, you need to know where a name comes from.

00:24 In this video, you’ll see the order the browser checks, and read the result in DevTools.

00:31 Scroll back up, right-click Rehearsals in the nav, and choose Inspect. In the sidebar of the Elements panel, open the Accessibility tab. Under Computed Properties, Name says Rehearsals, and Role says link.

00:46 Expand Name. The pane lists each source the browser could take a name from, in the order it checks them. The first two, aria-labelledby and aria-label, aren’t specified.

00:58 Contents gives Rehearsals, so that’s the name. The title row below it is crossed out, because once the browser finds a name, it stops looking.

01:09 Here’s the whole order, from the top. First, aria-labelledby points at other text on the page by its id. Nothing on the choir’s site uses it.

01:19 Second comes aria-label, a name written straight into an attribute. Narrow the preview to 390 pixels.

01:28 Now inspect the Menu button. Its only content is an icon marked aria-hidden, so it has no text of its own. Its name, Menu, comes from that attribute. The list of rows depends on the element, so a button’s differs from a link’s.

01:44 The footer’s Instagram link is built the same way, minus the aria-label. That’s why its name is empty.

01:52 Third is the element’s native label. Widen the preview again, open the Concerts page, and follow Sign up for the spring concert. Inspect the first field. Its name, Your name, comes from the label element tied to it.

02:07 A group of checkboxes takes its name from its legend the same way. Fourth is the content, for controls you press, such as links and buttons: they take their name from what’s inside them.

02:19 Fields and plain text don’t. That’s where Rehearsals came from. Last come title and placeholder, as last resorts. The email field has no label, so its name, Email, comes from its placeholder.

02:33 That works, but it’s a last resort for a reason, and the next lesson shows why.

02:41 The voice-part field comes next on the form. It’s a select with no label, and it shows Choose your voice part. Your turn: pause the video and predict the name the pane gives it.

02:57 It has no name at all. Its role, combobox, is the pane’s word for a select. A select is a field. Fields don’t take their name from their content, so the option’s text never counts.

03:11 The pane’s list for it has no Contents row.

03:16 The hint under the email field has an empty name too, and that’s fine. It’s a paragraph of text to read. It isn’t a control, so it needs no name. Watch out: a plain paragraph, div or span can’t take a name, so an aria-label on one doesn’t name it.

03:35 Here’s the rule: the browser checks each source in order and takes the first one that has text. When a name surprises you, the pane shows which source it came from.

03:46 So far, aria-label has named only a button with no visible text. Next comes Name Controls From Visible Text. There, you’ll see what happens when an aria-label meets the words on a control, and give the footer’s icon links their names.

Become a Member to join the conversation.