Providing Accessible Names and Descriptions
Introduction
Providing elements with accessible names, and where appropriate, accessible descriptions, is one of the most important responsibilities authors have when developing accessible web experiences. While doing so is straightforward for most elements, technical mistakes that can completely block users of assistive technologies are easy to make and unfortunately common. To help authors effectively provide accessible names and descriptions, this section explains their purpose, when authors need to provide them, how browsers assemble them, and rules for coding and composing them. It also guides authors in the use of the following naming and describing techniques and WAI-ARIA properties:
-
Naming:
- Naming with child content.
- Naming with a string attribute via
aria-label
. - Naming by referencing content with
aria-labelledby
. - Naming form controls with the label element.
- Naming fieldsets with the legend element.
- Naming tables and figures with captions.
- Fallback names derived from titles and placeholders.
-
Describing:
- Describing by referencing content with
aria-describedby
. - Describing tables and figures with captions.
- Descriptions derived from titles.
- Describing by referencing content with
What ARE Accessible Names and Descriptions?
An accessible name is a short string, typically 1 to 3 words, that authors associate with an element to provide users of assistive technologies with a label for the element. For example, an input field might have an accessible name of "User ID" or a button might be named "Submit".
An accessible name serves two primary purposes for users of assistive technologies, such as screen readers:
- Convey the purpose or intent of the element.
- Distinguish the element from other elements on the page.
Both the WAI-ARIA specification and WCAG require all focusable, interactive elements to have an accessible name. In addition dialogs and some structural containers, such as tables and regions, are required to have a name. Many other elements can be named, but whether a name will enhance the accessible experience is determined by various characteristics of the surrounding context. Finally, there are some elements where providing an accessible name is technically possible but not advisable. The Accessible Name Guidance by Role section lists naming requirements and guidelines for every ARIA role.
An accessible description is also an author-provided string that is rendered by assistive technologies. Authors supply a description when there is a need to associate additional information with an element, such as instructions or format requirements for an input field.
Assistive technologies present names differently from descriptions.
For instance, screen readers typically announce the name and role of an element first, e.g., a button named Mute Conversation
could be spoken as Mute Conversation button
.
If an element has a state, it could be announced either before or after the name and role; after name and role is the typical default.
For example, a switch button named Mute Conversation
in the off
state could be announced as Mute Conversation switch button off
.
Because descriptions are optional strings that are usually significantly longer than names, they are presented last, sometimes after a slight delay.
For example, Mute Conversation Switch button off, Silences alerts and notifications about activity in this conversation.
To reduce verbosity, some screen readers do not announce descriptions by default but instead inform users of their presence so that users can press a key that will announce the description.
How Are Name and Description Strings Derived?
Because there are several elements and attributes for specifying text to include in an accessible name or description string, and because authors can combine them in a practically endless number of ways, browsers implement fairly complex algorithms for assembling the strings. The sections on accessible name calculation and accessible description calculation explain the algorithms and how they implement precedence. However, most authors do not need such detailed understanding of the algorithms since nearly all circumstances where a name or description is useful are supported by the coding patterns described in the naming techniques and describing techniques sections.
Cardinal Rules of Naming
Rule 1: Heed Warnings and Test Thoroughly
Several of the naming techniques below include notes that warn against specific coding patterns that are either prohibited by the ARIA specification or fall into gray space that is not yet fully specified. Some of these prohibited or ambiguous patterns may appear logical and even yield desired names in some browsers. However, it is unlikely they will provide consistent results across browsers, especially over time as work to improve the consistency of name calculation across browsers progresses.
In addition to heeding the warnings provided in the naming techniques, it is difficult to over emphasize the importance of testing to ensure that names browsers calculate match expectations.
Rule 2: Prefer Visible Text
When a user interface includes visible text that could be used to provide an appropriate accessible name, using the visible text for the accessible name simplifies maintenance, prevents bugs, and reduces language translation requirements. When names are generated from text that exists only in markup and is never displayed visually, there is a greater likelihood that accessible names will not be updated when the user interface design or content are changed.
If an interactive element, such as an input field or button, does not have a visually persistent text label, consider adjusting the design to include one. In addition to serving as a more robust source for an accessible name, visible text labels enhance accessibility for many people with disabilities who do not use assistive technologies that present invisible accessible names. In most circumstances, visible text labels also make the user interface easier to understand for all users.
Rule 3: Prefer Native Techniques
In HTML documents, whenever possible, rely on HTML naming techniques, such as the HTML label
element for form elements and caption
element for tables.
While less flexible, their simplicity and reliance on visible text help ensure robust accessible experiences.
Several of the naming techniques highlight specific accessibility advantages of using HTML features instead of ARIA attributes.
Rule 4: Avoid Browser Fallback
When authors do not specify an accessible name using an element or attribute that is intended for naming, browsers attempt to help assistive technology users by resorting to fallback methods for generating a name.
For example, the HTML title
and placeholder
attributes are used as last resort sources of content for accessible names.
Because the purpose of these attributes is not naming, their content typically yields low quality accessible names that are not effective.
Rule 5: Compose Brief, Useful Names
Similar to how visually crowded screens and ambiguous icons reduce usability, excessively long, insufficiently distinct, or unclear accessible names can make a user interface very difficult, or even impossible, to use for someone who relies on a non-visual form of the user interface. In other words, for a web experience to be accessible, its accessible names must be effective. The section on Composing Effective and User-friendly Accessible Names provides guidance for balancing brevity and clarity.
Naming Techniques
Naming with Child Content
Certain elements get their name from the content they contain. For example, the following link is named "Home".
<a href="/">Home</a>
When assistive technologies render an element that gets its accessible name from its content, such as a link or button, the accessible name is the only content the user can perceive for that element. This is in contrast to other elements, such as text fields or tables, where the accessible name is a label that is presented in addition to the value or content of the element. For instance, the accessible name of a table can be derived from a caption element, and assistive technologies render both the caption and all other content contained inside the table.
Elements having one of the following roles are, by default, named by a string calculated from their descendant content:
- button
- cell
- checkbox
- columnheader
- gridcell
- heading
- link
- menuitem (content contained in a child
menu
element is excluded.) - menuitemcheckbox
- menuitemradio
- option
- radio
- row
- rowheader
- switch
- tab
- tooltip
- treeitem (content included in a child
group
element is excluded.)
When calculating a name from content for an element, user agents recursively walk through each of its descendant elements, calculate a name string for each descendant, and concatenate the resulting strings.
In two special cases, certain descendants are ignored: group
descendants of treeitem
elements and menu
descendants of menuitem
elements are omitted from the calculation.
For example, in the following tree
, the name of the first tree item is Fruits
; Apples
, Bananas
, and Oranges
are omitted.
<ul role="tree">
<li role="treeitem">Fruits
<ul role="group">
<li role="treeitem">Apples</li>
<li role="treeitem">Bananas</li>
<li role="treeitem">Oranges</li>
</ul>
</li>
</ul>
Warning
If an element with one of the above roles that supports naming from child content is named by using aria-label
or aria-labelledby
, content contained in the element and its descendants is hidden from assistive technology users unless the descendant content is referenced by aria-labelledby
.
It is strongly recommended to avoid using either of these attributes to override content of one of the above elements except in rare circumstances where hiding content from assistive technology users is beneficial.
In addition, in situations where visible content is hidden from assistive technology users by use of one of these attributes, thorough testing with assistive technologies is particularly important.
Naming with a String Attribute Via aria-label
The aria-label property enables authors to name an element with a string that is not visually rendered. For example, the name of the following button is "Close".
<button type="button" aria-label="Close">X</button>
The aria-label
property is useful when there is no visible text content that will serve as an appropriate accessible name.
The aria-label
property affects assistive technology users in one of two different ways, depending on the role of the element to which it is applied.
When applied to an element with one of the roles that supports naming from child content, aria-label
hides descendant content from assistive technology users and replaces it with the value of aria-label
.
However, when applied to nearly any other type of element, assistive technologies will render both the value of aria-label
and the content of the element.
For example, the name of the following navigation region is "Product".
<nav aria-label="Product">
<!-- list of navigation links to product pages -->
</nav>
When encountering this navigation region, a screen reader user will hear the name and role of the element, e.g., "Product navigation region", and then be able to read through the links contained in the region.
Warning
-
If
aria-label
is applied to an element with one of the roles that supports naming from child content, content contained in the element and its descendants is hidden from assistive technology users. It is strongly recommended to avoid usingaria-label
to override content of one of these elements except in rare circumstances where hiding content from assistive technology users is beneficial. -
There are certain types of elements, such as paragraphs and list items, that should not be named with
aria-label
. They are identified in the table in the Accessible Name Guidance by Role section. - Because the value of
aria-label
is not rendered visually, testing with assistive technologies to ensure the expected name is presented to users is particularly important. - When a user interface is translated into multiple languages, ensure that
aria-label
values are translated.
Naming with Referenced Content Via aria-labelledby
The aria-labelledby property enables authors to reference other elements on the page to define an accessible name. For example, the following switch is named by the text content of a previous sibling element.
<span id="night-mode-label">Night mode</span>
<span role="switch" aria-checked="false" tabindex="0" aria-labelledby="night-mode-label"></span>
Note that while using aria-labelledby
is similar in this situation to using an HTML label
element with the for
attribute, one significant difference is that browsers do not automatically make clicking on the labeling element activate the labeled element; that is an author responsibility.
However, HTML label
cannot be used to label a span
element.
Fortunately, an HTML input
with type="checkbox"
allows the ARIA switch
role, so when feasible, using the following approach creates a more robust solution.
<label for="night-mode">Night mode</label>
<input type="checkbox" role="switch" id="night-mode">
The aria-labelledby
property is useful in a wide variety of situations because:
- It has the highest precedence when browsers calculate accessible names, i.e., it overrides names from child content and all other naming attributes, including
aria-label
. - It can concatenate content from multiple elements into a single name string.
- It incorporates content from elements regardless of their visibility, i.e., it even includes content from elements with the HTML
hidden
attribute, CSSdisplay: none
, or CSSvisibility: hidden
in the calculated name string. - It incorporates the value of input elements, i.e., if it references a textbox, the value of the textbox is included in the calculated name string.
An example of referencing a hidden element with aria-labelledby
could be a label for a night switch control:
<span id="night-mode-label" hidden>Night mode</span>
<input type="checkbox" role="switch" aria-labelledby="night-mode-label">
In some cases, the most effective name for an element is its own content combined with the content of another element.
Because aria-labelledby
has highest precedence in name calculation, in those situations, it is possible to use aria-labelledby
to reference both the element itself and the other element.
In the following example, the "Read more..." link is named by the element itself and the article’s heading, resulting in a name for the link of "Read more... 7 ways you can help save the bees".
<h2 id="bees-heading">7 ways you can help save the bees</h2>
<p>Bees are disappearing rapidly. Here are seven things you can do to help.</p>
<p><a id="bees-read-more" aria-labelledby="bees-read-more bees-heading">Read more...</a></p>
When multiple elements are referenced by aria-labelledby
, text content from each referenced element is concatenated in the order specified in the aria-labelledby
value.
If an element is referenced more than one time, only the first reference is processed.
When concatenating content from multiple elements, browsers trim leading and trailing white space and separate content from each element with a single space.
<button id="download-button" aria-labelledby="download-button download-details">Download</button>
<span id="download-details">PDF, 2.4 MB</span>
In the above example, the accessible name of the button will be "Download PDF, 2.4 MB", with a space between "Download" and "PDF", and not "DownloadPDF, 2.4 MB".
Warning
- The
aria-labelledby
property cannot be chained, i.e., if an element witharia-labelledby
references another element that also hasaria-labelledby
, thearia-labelledby
attribute on the referenced element will be ignored. - If an element is referenced by
aria-labelledby
more than one time during a name calculation, the second and any subsequent references will be ignored. -
There are certain types of elements, such as paragraphs and list items, that should not be named with
aria-labelledby
. They are identified in the table in the Accessible Name Guidance by Role section. -
If
aria-labelledby
is applied to an element with one of the roles that supports naming from child content, content contained in the element and its descendants is hidden from assistive technology users unless it is also referenced byaria-labelledby
. It is strongly recommended to avoid using this attribute to override content of one of these elements except in rare circumstances where hiding content from assistive technology users is beneficial. - Because calculating the name of an element with
aria-labelledby
can be complex and reference hidden content, testing with assistive technologies to ensure the expected name is presented to users is particularly important.
Naming Form Controls with the Label Element
The HTML label
element enables authors to identify content that serves as a label and associate it with a form control.
When a label
element is associated with a form control, browsers calculate an accessible name for the form control from the label
content.
For example, text displayed adjacent to a checkbox may be visually associated with the checkbox, so it is understood as the checkbox label by users who can perceive that visual association.
However, unless the text is programmatically associated with the checkbox, assistive technology users will experience a checkbox without a label.
HTML provides two ways of associating a label with a form control.
The one that provides the broadest browser and assistive technology support is to set the for
attribute on the label
element to the id
of the control.
This way of associating the label with the control is often called explicit association.
<input type="checkbox" name="subscribe" id="subscribe_checkbox">
<label for="subscribe_checkbox">subscribe to our newsletter</label>
The other way, which is known as implicit association, is to wrap the checkbox and the labeling text in a label
element.
Some combinations of assistive technologies and browsers fail to treat the element as having an accessible name that is specified by using implicit association.
<label>
<input type="checkbox" name="subscribe">
subscribe to our newsletter
</label>
Using the label
element is an effective technique for satisfying Rule 2: Prefer Visible Text.
It also satisfies Rule 3: Prefer Native Techniques.
Native HTML labels offer an important usability and accessibility advantage over ARIA labeling techniques: browsers automatically make clicking the label equivalent to clicking the form control.
This increases the hit area of the form control.
Naming Fieldsets with the Legend Element
The HTML fieldset
element can be used to group form controls, and the legend
element can be used to give the group a name.
For example, a group of radio buttons can be grouped together in a fieldset
, where the legend
element labels the group for the radio buttons.
<fieldset>
<legend>Select your starter class</legend>
<label><input type="radio" name="starter-class" value="green">Green</label>
<label><input type="radio" name="starter-class" value="red">Red</label>
<label><input type="radio" name="starter-class" value="blue">Blue</label>
</fieldset>
This grouping technique is particularly useful for presenting multiple choice questions. It enables authors to associate a question with a group of answers. If a question is not programmatically associated with its answer options, assistive technology users may access the answers without being aware of the question.
Similar benefits can be gained from grouping and naming other types of related form fields using fieldset
and legend
.
<fieldset>
<legend>Shipping address</legend>
<p><label>Full name <input name="name" required></label></p>
<p><label>Address line 1 <input name="address-1" required></label></p>
<p><label>Address line 2 <input name="address-2"></label></p>
...
</fieldset>
<fieldset>
<legend>Billing address</legend>
...
</fieldset>
Using the legend
element to name a fieldset
element satisfies Rule 2: Prefer Visible Text and Rule 3: Prefer Native Techniques.
Fallback Names Derived from Titles and Placeholders
When an accessible name is not provided using one of the primary techniques (e.g., the aria-label
or aria-labelledby
attributes), or native markup techniques (e.g., the HTML label
element, or the alt
attribute of the HTML img
element), browsers calculate an accessible name from other attributes as a fallback mechanism.
Because the attributes used in fallback name calculation are not intended for naming, they typically yield low quality accessible names that are not effective.
So, As advised by Rule 4: Avoid Browser Fallback, prefer the explicit labeling techniques described above over fallback techniques described in this section.
Any HTML element can have a title
attribute specified.
The title
attribute may be used as the element's fallback accessible name.
The title
attribute is commonly presented visually as a tooltip when the user hovers over the element with a pointing device, which is not particularly discoverable, and is also not accessible to visual users without a pointing device.
For example, a fieldset
element without a legend
element child, but with a title
attribute, gets its accessible name from the title
attribute.
<fieldset title="Select your starter class">
<label><input type="radio" name="starter-class" value="green">Green</label>
<label><input type="radio" name="starter-class" value="red">Red</label>
<label><input type="radio" name="starter-class" value="blue">Blue</label>
</fieldset>
For the HTML input
and textarea
elements, the placeholder
attribute is used as a fallback labeling mechanism if nothing else (including the title
attribute) results in a label.
It is better to use a label
element, since it does not disappear visually when the user focuses the form control.
<!-- Using a <label> is recommended -->
<label>Search <input type=search name=q></label>
<!-- A placeholder is used as fallback -->
<input type=search name=q placeholder="Search">
Composing Effective and User-friendly Accessible Names
For assistive technology users, especially screen reader users, the quality of accessible names is one of the most significant contributors to usability. Names that do not provide enough information reduce users' effectiveness while names that are too long reduce efficiency. And, names that are difficult to understand reduce effectiveness, efficiency, and enjoyment.
The following guidelines provide a starting point for crafting user friendly names.
-
Convey function or purpose, not form.
For example, if an icon that looks like the letter
X
closes a dialog, name itClose
, notX
. Similarly, if a set of navigation links in the left side bar navigate among the product pages in a shopping site, name the navigation regionProduct
, notLeft
. -
Put the most distinguishing and important words first.
Often, for interactive elements that perform an action, this means a verb is the first word.
For instance, if a list of contacts displays
Edit
,Delete
, andActions
buttons for each contact, thenEdit John Doe
,Delete John Doe
, andActions for John Doe
would be better accessible names thanJohn Doe edit
,John Doe delete
, andJohn Doe actions
. By placing the verb first in the name, screen reader users can more easily and quickly distinguish the buttons from one another as well as from the element that opens the contact card for John Doe. - Be concise. For many elements, one to three words is sufficient. Only add more words when necessary.
-
Do NOT include a WAI-ARIA role name in the accessible name.
For example, do not include the word
button
in the name of a button, the wordimage
in the name of an image, or the wordnavigation
in the name of a navigation region. Doing so would create duplicate screen reader output since screen readers convey the role of an element in addition to its name. - Create unique names for elements with the same role unless the elements are actually identical. For example, ensure every link on a page has a different name except in cases where multiple links reference the same location. Similarly, give every navigation region on a page a different name unless there are regions with identical content that performs identical navigation functions.
- Start names with a capital letter; it helps some screen readers speak them with appropriate inflection. Do not end names with a period; they are not sentences.
Accessible Name Guidance by Role
Certain elements always require a name, others may usually or sometimes require a name, and still others should never be named. The table below lists all ARIA roles and provides the following information for each:
- Necessity of Naming
-
Indicates how necessary it is for authors to add a naming attribute or element to supplement or override the content of an element with the specified role.
This column may include one of the following values:
-
Required Only If Content Insufficient: An element with this role is named by its descendant content.
If
aria-label
oraria-labelledby
is applied, content contained in the element and its descendants is hidden from assistive technology users unless it is also referenced byaria-labelledby
. Avoid hiding descendant content except in the rare circumstances where doing so benefits assistive technology users. - Required: The ARIA specification requires authors to provide a name; a missing name causes accessibility validators to report an error.
- Recommended: Providing a name is strongly recommended.
- Discretionary: Naming is either optional or, in the circumstances described in the guidance column, is discouraged.
- Do Not Name: Naming is strongly discouraged even if it is technically permitted; often assistive technologies do not render a name even if provided.
- Prohibited: The ARIA specification does not permit the element to be named; If a name is specified, accessibility validators will report an error.
-
Required Only If Content Insufficient: An element with this role is named by its descendant content.
If
- Guidance:
- Provides information to help determine if providing a name is beneficial, and if so, describes any recommended techniques.
role | Necessity of Naming | Guidance |
---|---|---|
alert
|
Discretionary |
Some screen readers announce the name of an alert before announcing the content of the alert.
Thus, aria-label provides a method for prefacing the visible content of an alert with text that is not displayed as part of the alert.
Using aria-label is functionally equivalent to providing off-screen text in the contents of the alert, except off-screen text would be announced by screen readers that do not support aria-label on alert elements.
|
alertdialog
|
Required | Use aria-labelledby if a visible label is present, otherwise use aria-label . |
application
|
Required | Use aria-labelledby if a visible label is present, otherwise use aria-label . |
article
|
Recommended |
|
banner
|
Discretionary |
|
blockquote
|
Discretionary | If a visible label is present, associating it with the blockquote by using aria-labelledby could benefit some assistive technology users. |
button
|
Required Only If Content Insufficient |
|
caption
|
Prohibited | |
cell
|
Required Only If Content Insufficient |
|
checkbox
|
Required Only If Content Insufficient |
|
code
|
Prohibited | |
columnheader
|
Required Only If Content Insufficient |
|
combobox
|
Required |
|
complementary
|
Recommended |
|
contentinfo
|
Discretionary |
|
definition
|
Recommended | Reference the term being defined with role="term" , using aria-labelledby . |
deletion
|
Prohibited | |
dialog
|
Required | Use aria-labelledby if a visible label is present, otherwise use aria-label . |
directory
|
Discretionary |
|
document
|
Discretionary |
Elements with the document role are contained within an element with the application role, which is required to have a name.
Typically, the name of the application element will provide sufficient context and identity for the document element.
Because the application element is used only to create unusual, custom widgets, careful assessment is necessary to determine whether or not adding an accessible name is beneficial.
|
emphasis
|
Prohibited | |
feed
|
Recommended |
|
figure
|
Recommended |
|
form
|
Recommended |
|
generic
|
Prohibited | |
grid
|
Required |
|
gridcell
|
Required Only If Content Insufficient |
|
group
|
Discretionary |
|
heading
|
Required Only If Content Insufficient |
|
insertion
|
Prohibited | |
img
|
Required |
For the HTML img element, use the alt attribute.
For other elements with the img role, use aria-labelledby or aria-label .
|
link
|
Required Only If Content Insufficient |
|
list
|
Discretionary |
|
listbox
|
Required |
|
listitem
|
Do Not Name | Naming is not supported by assistive technologies; it is necessary to include relevant content within the list item. |
log
|
Discretionary |
Some screen readers announce the name of a log element before announcing the content of the log element.
Thus, aria-label provides a method for prefacing the visible content of a log element with text that is not displayed as part of the log element.
Using aria-label is functionally equivalent to providing off-screen text in the contents of the log element, except off-screen text would be announced by screen readers that do not support aria-label on log elements.
|
mark
|
Prohibited | |
main
|
Discretionary |
|
marquee
|
Discretionary | Use aria-labelledby if a visible label is present, otherwise use aria-label . |
math
|
Recommended |
|
menu
|
Recommended |
|
menubar
|
Recommended |
|
menuitem
|
Required Only If Content Insufficient |
|
menuitemcheckbox
|
Required Only If Content Insufficient |
|
menuitemradio
|
Required Only If Content Insufficient |
|
meter
|
Required |
|
navigation
|
Recommended |
|
none
|
Prohibited | An element with role="none" is not part of the accessibility tree (except in error cases). Do not use aria-labelledby or aria-label . |
note
|
Discretionary |
|
option
|
Required Only If Content Insufficient |
|
paragraph
|
Prohibited | |
presentation
|
Prohibited |
An element with role="presentation" is not part of the accessibility tree (except in error cases).
Do not use aria-labelledby or aria-label .
|
progressbar
|
Required |
|
radio
|
Required Only If Content Insufficient |
|
radiogroup
|
Required |
|
region
|
Required |
|
row
|
Required Only If Content Insufficient AND descendant of a treegrid AND the row is focusable |
When row elements are focusable in a treegrid, screen readers announce the entire contents of a row when navigating by row.
This is typically the most appropriate behavior.
However, in some circumstances, it could be beneficial to change the order in which cells are announced or exclude announcement of certain cells by using aria-labelledby to specify which cells to announce.
|
rowgroup
|
Do Not Name | Naming is not supported by assistive technologies. |
rowheader
|
Required Only If Content Insufficient |
|
scrollbar
|
Discretionary |
|
search
|
Recommended |
|
searchbox
|
Required |
|
separator
|
Discretionary |
|
slider
|
Required |
|
spinbutton
|
Required |
|
status
|
Discretionary |
Some screen readers announce the name of a status element before announcing the content of the status element.
Thus, aria-label provides a method for prefacing the visible content of a status element with text that is not displayed as part of the status element.
Using aria-label is functionally equivalent to providing off-screen text in the contents of the status element, except off-screen text would be announced by screen readers that do not support aria-label on status elements.
|
strong
|
Prohibited | |
subscript
|
Prohibited | |
superscript
|
Prohibited | |
switch
|
Required Only If Content Insufficient |
|
tab
|
Required Only If Content Insufficient |
|
table
|
Required |
|
tablist
|
Recommended |
|
tabpanel
|
Required |
|
term
|
Do Not Name | Since a term is usually the name for the role="definition" element, it could be confusing if the term itself also has a name. |
textbox
|
Required |
|
time
|
Do Not Name | Naming is not supported by assistive technologies. |
timer
|
Discretionary |
Some screen readers announce the name of a timer element before announcing the content of the timer element.
Thus, aria-label provides a method for prefacing the visible content of a timer element with text that is not displayed as part of the timer element.
Using aria-label is functionally equivalent to providing off-screen text in the contents of the timer element, except off-screen text would be announced by screen readers that do not support aria-label on timer elements.
|
toolbar
|
Recommended |
|
tooltip
|
Required Only If Content Insufficient |
|
tree
|
Required |
|
treegrid
|
Required |
|
treeitem
|
Required Only If Content Insufficient |
|
Accessible name calculation
User agents construct an accessible name string for an element by walking through a list of potential naming methods and using the first that generates a name. The algorithm they follow is defined in the accessible name specification. It is roughly like the following:
-
The
aria-labelledby
property is used if present. -
If the name is still empty, the
aria-label
property is used if present. -
If the name is still empty, then host-language-specific attributes or elements are used if present. For HTML, these are, depending on the element:
input
whosetype
attribute is in the Button, Submit Button, or Reset Button state- The
value
attribute. input
whosetype
attribute is in the Image Button stateimg
area
- The
alt
attribute. fieldset
- The first child
legend
element. - Other form elements
- The associated
label
element(s). figure
- The first child
figcaption
element. table
- The first child
caption
element.
If the name is still empty, then for elements with a role that supports naming from child content, the content of the element is used.
-
Finally, if the name is still empty, then other fallback host-language-specific attributes or elements are used if present. For HTML, these are, depending on the element:
input
whosetype
attribute is in the Text, Password, Search, Telephone, or URL statestextarea
-
The
title
attribute. Otherwise, theplaceholder
attribute. input
whosetype
attribute is in the Submit Button state- A localized string of the word "submit".
input
whosetype
attribute is in the Reset Button state- A localized string of the word "reset".
input
whosetype
attribute is in the Image Button state-
The
title
attribute. Otherwise, a localized string of the phrase "Submit Query". summary
- The word "Details".
- Other elements
- The
title
attribute.
The final step is a fallback mechanism. Generally when labeling an element, use one of the non-fallback mechanisms.
When calculating a name from content, the user agent walks through all descendant nodes except in the cases of treeitem
and menuitem
as described below.
And, when following references in an aria-labelledby
attribute, it similarly walks the tree of each referenced element.
Thus, the naming algorithm is recursive.
The following two sections explain non-recursive and recursive examples of how the algorithm works.
When calculating a name from content for the treeitem
role, descendant content of child group
elements are not included.
For example, in the following tree
, the name of the first tree item is Fruits
; Apples
, Bananas
, and Oranges
are automatically omitted.
<ul role="tree">
<li role="treeitem">Fruits
<ul role="group">
<li role="treeitem">Apples</li>
<li role="treeitem">Bananas</li>
<li role="treeitem">Oranges</li>
</ul>
</li>
</ul>
Similarly, when calculating a name from content for the menuitem
role, descendant content of child menu
elements are not included.
So, the name of the first parent menuitem
in the following menu
is Fruits
.
<ul role="menu">
<li role="menuitem">Fruits
<ul role="menu">
<li role="menuitem">Apples</li>
<li role="menuitem">Bananas</li>
<li role="menuitem">Oranges</li>
</ul>
</li>
</ul>
Examples of non-recursive accessible name calculation
Consider an input
element that has no associated label
element and only a name
attribute and so does not have an accessible name (do not do this):
<input name="code">
If there is a placeholder
attribute, then it serves as a naming fallback mechanism (avoid doing this):
<input name="code"
placeholder="One-time code">
If there is also a title
attribute, then it is used as the accessible name instead of placeholder
, but it is still a fallback (avoid doing this):
<input name="code"
placeholder="123456"
title="One-time code">
If there is also a label
element (recommended), then that is used as the accessible name, and the title
attribute is instead used as the accessible description:
<label>One-time code
<input name="code"
placeholder="123456"
title="Get your code from the app.">
</label>
If there is also an aria-label
attribute (not recommended unless it adds clarity for assistive technology users), then that becomes the accessible name, overriding the label
element:
<label>Code
<input name="code"
aria-label="One-time code"
placeholder="123456"
title="Get your code from the app.">
</label>
If there is also an aria-labelledby
attribute, that wins over the other elements and attributes (the aria-label
attribute ought to be removed if it is not used):
<p>Please fill in your <span id="code-label">one-time code</span> to log in.</p>
<p>
<label>Code
<input name="code"
aria-labelledby="code-label"
aria-label="This is ignored"
placeholder="123456"
title="Get your code from the app.">
</label>
</p>
Examples of recursive accessible name calculation
The accessible name calculation algorithm will be invoked recursively when necessary.
An aria-labelledby
reference causes the algorithm to be invoked recursively, and when computing an accessible name from content the algorithm is invoked recursively for each child node.
In this example, the label for the button is computed by recursing into each child node, resulting in Move to trash
.
<button>Move to <img src="bin.svg" alt="trash"></button>
When following an aria-labelledby
reference, the algorithm avoids following the same reference twice to avoid infinite loops.
In this example, the label for the button is computed by first following the aria-labelledby
reference to the parent element, and then computing the label for that element from the child nodes, first visiting the button
element again but ignoring the aria-labelledby
reference and instead using the aria-label
, and then visiting the next child (the text node).
The resulting label is Remove meeting: Daily status report
.
<div id="meeting-1">
<button aria-labelledby="meeting-1" aria-label="Remove meeting:">X</button>
Daily status report
</div>
Describing Techniques
Describing by referencing content with aria-describedby
The aria-describedby
property works similarly to the aria-labelledby
property.
For example, a button could be described by a sibling paragraph.
<button aria-describedby="trash-desc">Move to trash</button>
...
<p id="trash-desc">Items in the trash will be permanently removed after 30 days.</p>
Descriptions are reduced to text strings.
For example, if the description contains an HTML img
element, a text equivalent of the image is computed.
<button aria-describedby="trash-desc">Move to <img src="bin.svg" alt="trash"></button>
...
<p id="trash-desc">Items in <img src="bin.svg" alt="the trash"> will be permanently removed after 30 days.</p>
As with aria-labelledby
, it is possible to reference an element using aria-describedby
even if that element is hidden.
For example, a text field in a form could have a description that is hidden by default, but can be revealed on request using a disclosure widget.
The description could also be referenced from the text field directly with aria-describedby
.
In the following example, the accessible description for the input
element is Your username is the name that you use to log in to this service.
<label for="username">Username</label>
<input id="username" name="username" aria-describedby="username-desc">
<button aria-expanded="false" aria-controls="username-desc" aria-label="Help about username">?</button>
<p id="username-desc" hidden>
Your username is the name that you use to log in to this service.
</p>
Descriptions Derived from Titles
If an accessible description was not provided using the aria-describedby
attribute or one of the primary host-language-specific attributes or elements (e.g., the caption
element for table
), then, for HTML, if the element has a title
attribute, that is used as the accessible description.
A visible description together with aria-describedby
is generally recommended.
If a description that is not visible is desired, then the title
attribute can be used, for any HTML element that can have an accessible description.
Note that the title
attribute might not be accessible to some users, in particular sighted users not using a screen reader and not using a pointing device that supports hover (e.g., a mouse).
For example, an input
element with input constrained using the pattern
attribute can use the title
attribute to describe what the expected input is.
<label> Part number:
<input pattern="[0-9][A-Z]{3}" name="part"
title="A part number is a digit followed by three uppercase letters."/>
</label>
The title
attribute in this case can be shown to the user as a tooltip when the user hovers or focuses the control, but also as part of the error message when the user agent validates the form, if the input
element's value doesn't match the pattern
.
As another example, a link can use the title
attribute to describe the link in more detail.
<a href="http://twitter.com/W3C"
title="Follow W3C on Twitter">
<img src="/2008/site/images/Twitter_bird_logo_2012.svg"
alt="Twitter" class="social-icon" height="40" />
</a>
Accessible description calculation
Like the accessible name calculation, the accessible description calculation produces a text string.
The accessible description calculation algorithm is the same as the accessible name calculation algorithm except for a few branch points that depend on whether a name or description is being calculated.
In particular, when accumulating text for an accessible description, the algorithm uses aria-describedby
instead of aria-labelledby
.
User agents construct an accessible description string for an element by walking through a list of potential description methods and using the first that generates a description. The algorithm they follow is defined in the accessible name specification. It is roughly like the following:
-
The
aria-describedby
property is used if present. -
If the description is still empty, then host-language-specific attributes or elements are used if present, if it wasn't already used as the accessible name. For HTML, these are, depending on the element:
input
whosetype
attribute is in the Button, Submit Button, or Reset Button state- The
value
attribute. summary
- The element's subtree.
table
- The first child
caption
element.
-
Finally, if the description is still empty, then other host-language-specific attributes or elements are used if present, if it wasn't already used for the accessible name. For HTML, this is the
title
attribute.