Accessible Names
An accessible name is a text that is programmatically associated with an element and that is exposed by the browser to assistive technologies via the accessibility tree. It should identify the element it is associated with in an an concise way. In contrast a label is the visible element that gets presented or displayed to users. 1
Naming Principles
- The accessible name must contain or be equal the label that is presented visually. 2
- Interactive Elements must have an accessible name, while non-interactive elements sometimes also need accessible names, like duplicate landmark regions, tables, dialogs or groups 3
- Non-interactive text-level semantic elements and generic elements like <div> or<span> elements should not have an accessible name. 4 10
- It is possible to label lists wit aria-label, though support of that is not widespread. So it is always better to change your design to allow for visual labeling. 11
Naming Method Hierarchy
There is a hierarchy of methods that gets used to commutate the accessible name. The following list defines the approximate order of naming methods that gets used by browsers. 5 The first method having the highest precedence, the last method having the lowest precedence. However the exact methods that get used differ between elements. For a exact and complete list of all elements and their naming methods see the source reference of this paragraph. 5
- aria-labelledby:
- Can reference one or more HTML element ids, including it‘s own. The name is then concatenated from the referenced elements names in the order specified.
- The best use of aria-labelledby is on visible elements. But a common way of using this attribute as well is to create a hidden element that get used by aria-labelledby to create a label for the element. For example for <button> elements that only consist of a visible icon. This is a more robust way than using aria-label since it suffers less from the disadvantages of the aria-label attribute. 5
- aria-label:
- Derive name from another element:
- Using programmatically connected elements like <label> for <input> elements or <caption> for <table> elements and so on gives the element an accessible name.
- Derive name from an attribute (except title):
- This includes attributes like the
alt
attribute for <img> elements or thevalue
attribute for <input type="submit"> elements.
- This includes attributes like the
- Derive name from the elements content:
- Elements like <button> or <a> can use it‘s content if it is text or has an element with an accessible name.
- Many elements don‘t use this method to compute their accessible name. 5
- Careful: Text or icons added through pseudo elements will also get included in the name.
- title attribute:
- Using the title attribute as means of an accessible name is currently not recommended, due to the lack of consistent support. 7
What naming method to use
Adrian Roselli among others uses this priority when naming elements: 6
- Native HTML techniques, which includes
- Derive name from other elements
- Derive name from an attribute (except title)
- Derive name from the elements content
- aria-labelledby pointing at existing visible text
- visibly-hidden element content that is still in the page
- aria-label
It is always the by far most accessible solution to use visible elements for accessible names. Before using hidden elements or the aria-label attribute, you should first reconsider if you design can be made more inclusive by adding a visible label. One example of this would be icon only buttons. It would be more inclusive if the button also had a visible text label permanently shown or at least on focus. 9
Sources
- WebAIM: Decoding Label and Name for Accessibility © WebAIM
- W3C: Label in Name (Level A) by Accessibility Guidelines Working Group (AG WG) Participants is licensed under W3C Document License
- W3C: Info and Relationships (Level A) by Accessibility Guidelines Working Group (AG WG) Participants is licensed under W3C Document License
- Scott Ohara: Name, labels, ARIA, what to do? by Scott Ohara
- W3C: 4. Accessible Name and Description Computation is licensed under W3C Document License
- Adrian Roselli: My Priority of Methods for Labeling a Control by Adrian Roselli © Adrian Roselli
- 24 Accessibility: The Trials and Tribulations of the Title Attribute by Scott O’Hara
- Eric Bailey: aria-label is a code smell by Eric Bailey
- Sara Soueidan: Accessible Text Labels For All by Sara Soueidan © Sara Soueidan
- Practical Support: aria-label, aria-labelledby and aria-describedby by Accessibility Guidelines Working Group (AG WG) Participants is licensed under W3C Document License
- Scott Ohara: Results of labeling lists (and list items!) by Scott Ohara