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:
aria-label
.aria-labelledby
.aria-describedby
.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:
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.
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 ThoroughlySeveral 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 TextWhen 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 TechniquesIn 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.
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.
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 ContentCertain 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:
menu
element is excluded.)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.
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.
Warningaria-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 using aria-label
to override content of one of these elements except in rare circumstances where hiding content from assistive technology users is beneficial.aria-label
. They are identified in the table in the Accessible Name Guidance by Role section.aria-label
is not rendered visually, testing with assistive technologies to ensure the expected name is presented to users is particularly important.aria-label
values are translated.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:
aria-label
.hidden
attribute, CSS display: none
, or CSS visibility: hidden
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".
Warningaria-labelledby
property cannot be chained, i.e., if an element with aria-labelledby
references another element that also has aria-labelledby
, the aria-labelledby
attribute on the referenced element will be ignored.aria-labelledby
more than one time during a name calculation, the second and any subsequent references will be ignored.aria-labelledby
. They are identified in the table in the Accessible Name Guidance by Role section.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 by aria-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.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.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.
The accessible name for HTML table
and figure
elements can be derived from a child caption
or figcaption
element, respectively. Tables and figures often have a caption to explain what they are about, how to read them, and sometimes giving them numbers used to refer to them in surrounding prose. Captions can help all users better understand content, but are especially helpful to users of assistive technologies.
In HTML, the table
element marks up a data table, and can be provided with a caption using the caption
element. If the table
element does not have aria-label
or aria-labelledby
, then the caption
will be used as the accessible name. For example, the accessible name of the following table is Special opening hours
.
<table>
<caption>Special opening hours</caption>
<tr><td>30 May</td><td>Closed</td></tr>
<tr><td>6 June</td><td>11:00-16:00</td></tr>
</table>
The following example gives the table a number (Table 1
) so it can be referenced.
<table>
<caption>Table 1. Traditional dietary intake of Okinawans and other Japanese circa 1950</caption>
<thead>
<tr>
<th></th>
<th>Okinawa, 1949</th>
<th>Japan, 1950</th>
</tr>
</thead>
<tbody>
<tr>
<th>Total calories</th>
<td>1785</td>
<td>2068</td>
[...]
</table>
Note: Above table content is from Caloric restriction, the traditional Okinawan diet, and healthy aging: the diet of the world's longest-lived people and its potential impact on morbidity and life span.
If a table
is named using aria-label
or aria-labelledby
, then a caption
element, if present, will become an accessible description. For an example, see Describing Tables and Figures with Captions.
Similarly, an HTML figure
element can be given a caption using the figcaption
element. The caption can appear before or after the figure, but it is more common for figures to have the caption after.
<figure>
<img alt="Painting of a person walking in a desert." src="Hole_JesusalDesierto.jpg">
<figcaption>Jesus entering the desert as imagined by William Hole, 1908</figcaption>
</figure>
Like with table
elements, if a figure
is not named using aria-label
or aria-labelledby
, the content of the figcaption
element will be used as the accessible name. However unlike table
elements, if the figcaption
element is not used for the name, it does not become an accessible description unless it is referenced by aria-describedby
. Nevertheless, assistive technologies will render the content of a figcaption
regardless of whether it is used as a name, description, or neither.
Using the caption
element to name a table
element, or a figcaption
element to name a figure
element, satisfies Rule 2: Prefer Visible Text and Rule 3: Prefer Native Techniques.
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.
Xcloses a dialog, name it
Close, not
X. Similarly, if a set of navigation links in the left side bar navigate among the product pages in a shopping site, name the navigation region
Product, not
Left.
Edit,
Delete, and
Actionsbuttons for each contact, then
Edit John Doe,
Delete John Doe, and
Actions for John Doewould be better accessible names than
John Doe edit,
John Doe delete, and
John 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.
buttonin the name of a button, the word
imagein the name of an image, or the word
navigationin 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.
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:
aria-label
or aria-labelledby
is applied, content contained in the element and its descendants is hidden from assistive technology users unless it is also referenced by aria-labelledby
. Avoid hiding descendant content except in the rare circumstances where doing so benefits assistive technology users.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
aria-labelledby
if a visible label is present, otherwise use aria-label
.banner
Discretionary
aria-labelledby
if a visible label is present, otherwise with aria-label
.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
aria-label
or aria-labelledby
will hide descendant content from assistive technologies.caption
Prohibited cell
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide descendant content from assistive technologies.cell
; the name of a cell in a table is its content. Headers are complementary information.checkbox
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide any descendant content from assistive technologies.type="checkbox"
, use a label
element.aria-labelledby
.code
Prohibited columnheader
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide descendant content from assistive technologies.columnheader
role is implied from an HTML th
, the HTML abbr
attribute can be used to specify an abbreviated version of the name that is only announced when screen readers are reading an associated cell
within the table
, grid
, or treegrid
.combobox
Required
combobox
role is applied to an HTML select
or input
element, can be named with an HTML label
element.aria-labelledby
if a visible label is present.aria-label
if a visible label is not present.complementary
Recommended
aria-labelledby
if a visible label is present, otherwise use aria-label
.contentinfo
Discretionary
aria-labelledby
if a visible label is present, otherwise with aria-label
.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
aria-labelledby
if a visible label is present, otherwise use aria-label
.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
aria-labelledby
if a visible label is present, otherwise use aria-label
.figure
Recommended
figure
and figcaption
elements. The figcaption
will serve as the accessible name for the figure
. See the Naming Tables and Figures with Captions section.aria-labelledby
on the figure, pointing to the figure's caption.aria-label
can be used.form
Recommended
aria-labelledby
if a visible label is present, otherwise use aria-label
.generic
Prohibited grid
Required
grid
is applied to an HTML table
element, then the accessible name can be derived from the table's caption
element.aria-labelledby
if a visible label is present, otherwise use aria-label
.gridcell
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide descendant content from assistive technologies.gridcell
; the name of a cell in a grid is its content. Headers are complementary information.group
Discretionary
fieldset
element, the accessible name can be derived from the legend
element.details
element, do not provide an accessible name for this element. The user interacts with the summary
element, and that can derive its accessible name from its contents.optgroup
element, use the label
attribute.aria-labelledby
if a visible label is present, otherwise use aria-label
.heading
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide descendant content from assistive technologies.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
aria-label
or aria-labelledby
will hide descendant content from assistive technologies.list
Discretionary
aria-labelledby
if a visible label is present, otherwise with aria-label
.listbox
Required
listbox
role is applied to an HTML select
element (with the multiple
attribute or a size
attribute having a value greater than 1), can be named with an HTML label
element.aria-labelledby
if a visible label is present.aria-label
if a visible label is not present.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
aria-labelledby
if a visible label is present, otherwise with aria-label
.marquee
Discretionary Use aria-labelledby
if a visible label is present, otherwise use aria-label
. math
Recommended
math
element has only presentational children and the accessible name is intended to convey the mathematical expression, use aria-label
to provide a string that represents the expression.math
element contains navigable content that conveys the mathematical expression and a visible label for the expression is present, use aria-labelledby
.aria-label
to name the expression, e.g., aria-label="Pythagorean Theorem"
.menu
Recommended
aria-labelledby
to refer to the menuitem or button that controls this element's display.aria-label
.menubar
Recommended
menuitem
elements in a menubar
. Naming a menubar
is comparable to naming a menu button. The name of a button
that opens a menu
conveys the purpose of the menu it opens. Since a menubar
element is displayed persistently, a name on the menubar
can serve that same purpose.aria-labelledby
if a visible label is present, otherwise use aria-label
.menuitem
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide any descendant content from assistive technologies.menu
is automatically excluded from the accessible name calculation.menuitemcheckbox
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide any descendant content from assistive technologies.menuitemradio
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide any descendant content from assistive technologies.meter
Required
meter
element, can be named with an HTML label
element.aria-labelledby
if a visible label is present.aria-label
if a visible label is not present.navigation
Recommended
aria-labelledby
if a visible label is present, otherwise use aria-label
.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
aria-labelledby
if a visible label is present, otherwise with aria-label
.option
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide any descendant content from assistive technologies.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
progressbar
role is applied to an HTML progress
element, can be named with an HTML label
element.aria-labelledby
if a visible label is present.aria-label
if a visible label is not present.radio
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide any descendant content from assistive technologies.type="checkbox"
, use a label
element.aria-labelledby
.radiogroup
Required
radio
buttons.aria-labelledby
if a visible label is present, otherwise use aria-label
.region
Required
aria-labelledby
if a visible label is present, otherwise use aria-label
.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
aria-label
or aria-labelledby
will hide descendant content from assistive technologies.rowheader
role is implied from an HTML th
, the HTML abbr
attribute can be used to specify an abbreviated version of the name that is only announced when screen readers are reading an associated cell
within the table
, grid
, or treegrid
.scrollbar
Discretionary
aria-controls
attribute, which is required for scrollbar
.aria-labelledby
if a visible label is present, otherwise with aria-label
.search
Recommended
aria-labelledby
if a visible label is present, otherwise with aria-label
.searchbox
Required
searchbox
role is applied to an HTML input
element, can be named with an HTML label
element.aria-labelledby
if a visible label is present.aria-label
if a visible label is not present.separator
Discretionary
separator
element on the page.aria-labelledby
if a visible label is present, otherwise with aria-label
.slider
Required
slider
role is applied to an HTML input
element, can be named with an HTML label
element.aria-labelledby
if a visible label is present.aria-label
if a visible label is not present.spinbutton
Required
textbox
role is applied to an HTML input
element, can be named with an HTML label
element.aria-labelledby
if a visible label is present.aria-label
if a visible label is not present.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
aria-label
or aria-labelledby
will hide any descendant content from assistive technologies.type="checkbox"
, use a label
element.aria-labelledby
.tab
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide descendant content from assistive technologies.table
Required
table
element, use the caption
element.aria-labelledby
if a visible label is present.aria-label
if a visible label is not present.tablist
Recommended
aria-labelledby
if a visible label is present, otherwise use aria-label
.tabpanel
Required
aria-labelledby
pointing to the tab
element that controls the tabpanel
.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
textbox
role is applied to an HTML input
or textarea
element, can be named with an HTML label
element.aria-labelledby
if a visible label is present.aria-label
if a visible label is not present.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
toolbar
element on the page, naming is required.aria-labelledby
if a visible label is present, otherwise use aria-label
.tooltip
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide descendant content from assistive technologies.tree
Required
aria-labelledby
if a visible label is present, otherwise use aria-label
.treegrid
Required
treegrid
is applied to an HTML table
element, then the accessible name can be derived from the table's caption
element.aria-labelledby
if a visible label is present, otherwise use aria-label
.treeitem
Required Only If Content Insufficient
aria-label
or aria-labelledby
will hide any descendant content from assistive technologies.group
is automatically excluded from the 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
whose type
attribute is in the Button, Submit Button, or Reset Button state
value
attribute.
input
whose type
attribute is in the Image Button state
img
area
alt
attribute.
fieldset
legend
element.
label
element(s).
figure
figcaption
element.
table
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
whose type
attribute is in the Text, Password, Search, Telephone, or URL states
textarea
title
attribute. Otherwise, the placeholder
attribute.
input
whose type
attribute is in the Submit Button state
input
whose type
attribute is in the Reset Button state
input
whose type
attribute is in the Image Button state
title
attribute. Otherwise, a localized string of the phrase "Submit Query".
summary
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>
Describing Tables and Figures with Captions
In HTML, if the table
is named using aria-label
or aria-labelledby
, a child caption
element becomes an accessible description. For example, a preceding heading might serve as an appropriate accessible name, and the caption
element might contain a longer description. In such a situation, aria-labelledby
could be used on the table
to set the accessible name to the heading content and the caption
would become the accessible description.
<h2 id="events-heading">Upcoming events</h2>
<table aria-labelledby="events-heading">
<caption>
Calendar of upcoming events, weeks 27 through 31, with each week starting with
Monday. The first column is the week number.
</caption>
<tr><th>Week</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th></tr>
<tr><td>27</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>28</td><td></td><td></td><td></td><td></td><td></td><td></td><td><a href="/events/9856">Crown Princess's birthday</a></td></tr>
<tr><td>29</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>30</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>31</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</table>
The HTML figure
element can get its accessible name from its figcaption
element, but it will not be used as the accessible description, even if it was not used as the accessible name. If the figcaption
element is appropriate as an accessible description, and the accessible name is set using aria-labelledby
or aria-label
, then the figcaption
can be explicitly set as the accessible description using the aria-describedby
attribute.
<h2 id="neutron">Neutron</h2>
<figure aria-labelledby="neutron" aria-describedby="neutron-caption">
<img src="neutron.svg" alt="Within the neutron are three quarks (blue 'u', red 'd', green 'd') that are interconnected.">
<figcaption id="neutron-caption">
The quark content of the neutron. The color assignment of individual quarks is
arbitrary, but all three colors must be present. Forces between quarks are
mediated by gluons.
</figcaption>
</figure>
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
whose type
attribute is in the Button, Submit Button, or Reset Button state
value
attribute.
summary
table
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4