diff --git a/aria-practices.html b/aria-practices.html index c9d80f7c57..4ce1dbba82 100644 --- a/aria-practices.html +++ b/aria-practices.html @@ -337,12 +337,12 @@
page
.
If the element representing the current page is not a link, aria-current is optional.
@@ -397,7 +397,7 @@ + Note: This is a draft of a new section. + Please provide feedback in + issue 1050. +
++ Providing elements with accessible names, and where appropriate, accessible descriptions is one of the most fundamental and important responsibilities authors have when developing accessible web experiences. + While doing so is straightforward for most elements, technical mistakes that can have devastating impacts on users of assistive technologies are easy to make and unfortunately common. + To help authors provide effective and reliable 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 provides guidance for effectively employing the following naming and describing techniques and WAI-ARIA properties: +
+aria-label
.aria-labelledby
.aria-describedby
.aria-details
.+ 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. + Because they are usually significantly longer than names, assistive technologies present descriptions differently from names and other element attributes. + For instance, a screen reader may announce a description of an element after its name, role, value (if any), and relevant states or properties. +
++ 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 provide detailed explanations of the algorithms. +However, most authors do not need 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. +
++ 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. +
++ 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. +
+
+ In HTML documents, whenever possible, rely on HTML naming techniques, such as the HTML label
element, alt
attribute for images, caption
element for tables, etc.
+ While less flexible, their simplicity and reliance on visible text help ensure robust accessible experiences.
+
+ 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. +
++ 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:
+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>
+
+
+ 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. +
+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 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:
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, CSS display: none
, or CSS visibility: 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".
+aria-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.
+ Wrapping the checkbox and the labeling text in a label
element as follows gives the checkbox an accessible name.
+
+ <label>
+ <input type="checkbox" name="subscribe">
+ subscribe to our newsletter
+ </label>
+
+
+ A form control can also be associated with a label by using the for
attribute on the label
element.
+ This allows the label and the form control to be siblings or have different parents in the DOM, but requires adding an id
attribute to the form control, which can be error-prone.
+ When possible, use the above encapsulation technique for association instead of the following for
attribute technique.
+
+ <input type="checkbox" name="subscribe" id="subscribe_checkbox">
+ <label for="subscribe_checkbox">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 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 name="starter-class" value="green"> Green</label>
+ <label><input name="starter-class" value="red"> Red</label>
+ <label><input 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.
+ 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.
+ It is recommended authors 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 name="starter-class" value="green"> Green</label>
+ <label><input name="starter-class" value="red"> Red</label>
+ <label><input 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">
+ + 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.
+ 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 | +
+
|
+
button |
+ Required Only If Content Insufficient | +
+
|
+
cell |
+ Required Only If Content Insufficient | +
+
|
+
checkbox |
+ Required Only If Content Insufficient | +
+
|
+
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 . |
+
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.
+ |
+
feed |
+ Recommended | +
+
|
+
figure |
+ Recommended | +
+
|
+
form |
+ Recommended | +
+
|
+
grid |
+ Required | +
+
|
+
gridcell |
+ Required Only If Content Insufficient | +
+
|
+
group |
+ Discretionary | +
+
|
+
heading |
+ Required Only If Content Insufficient | +
+
|
+
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 | +Not supported by assistive technologies; it is necessary to include relevant content within the list item. | +
log |
+ Required | +Use aria-labelledby if a visible label is present, otherwise use aria-label . |
+
main |
+ Discretionary | +
+
|
+
marquee |
+ Required | +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 | +
+
|
+
navigation |
+ Recommended | +
+
|
+
none |
+ Do Not Name | +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 | +
+
|
+
presentation |
+ Do Not Name | +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 | +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.
+ |
+
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 | +
+
|
+
timer |
+ Required | +Use aria-labelledby if a visible label is present, otherwise use aria-label . |
+
toolbar |
+ Recommended | +
+
|
+
tooltip |
+ Required Only If Content Insufficient | +
+
|
+
tree |
+ Required | +
+
|
+
treegrid |
+ Required | +
+
|
+
treeitem |
+ Required Only If Content Insufficient | +
+
|
+
+ 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 statevalue
attribute.input
whose type
attribute is in the Image Button stateimg
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 statestextarea
title
attribute. Otherwise, the placeholder
attribute.input
whose type
attribute is in the Submit Button stateinput
whose type
attribute is in the Reset Button stateinput
whose type
attribute is in the Image Button statetitle
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>
+
+
+ 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>
+ 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>
+
+ 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>
+
+ aria-details
+ In some cases, a plain text description is insufficient. + The aria-details property can be used in such situations. + In the following example, a text field for a passenger’s name (when booking a flight) has a description that is a list of three items, and contains a link to an external document with further details. +
+ +
+ <ul id="full-name-desc">
+ <li>The passenger's name must match the name in their passport.</li>
+ <li>The name must consist of only characters in the A-Z range.</li>
+ <li><a href="faq.html#name">What if the name in the passport contains other characters?</a></li>
+ </ul>
+ <fieldset>
+ <legend>Passenger 1 (adult)</legend>
+ <p>
+ <label>Full name <input name="full-name" aria-details="full-name-desc"></label>
+ </p>
+ ...
+ </fieldset>
+
+
+
+ If both aria-details
and aria-describedby
are specified on an element, browsers ignore the aria-describedby
value when calculating the accessible description.
+ Specifying both is potentially useful if there is a need to provide a fallback description for browsers and assistive technologies that do not yet support aria-details
.
+
If the aria-details
attribute is not used, and 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
or aria-details
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>
+
+ Like the accessible name calculation, the accessible description calculation produces a text string.
+ However, there is one exception: when an element is described using the aria-details
attribute the assistive technology is provided with a reference instead of constructing a flattened 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
.
+
+ When aria-details
is not used, 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 statevalue
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.
@@ -4216,7 +5722,7 @@
Work to draft content for this section is tracked in issue 219.
-The first goal when designing a keyboard interface is simple, efficient, and intuitive operation with only basic keyboard navigation support. If basic operation of a keyboard interface is inefficient , attempting to compensate for fundamental design issues, such as suboptimal layout or command structure, by implementing keyboard shortcuts will not likely reduce user frustration. The practical implication of this is that, in most well-designed user interfaces, the percentage of functionality that needs to be accessible via a keyboard shortcut in order to create optimal usability is not very high. In many simple user interfaces, keyboard shortcuts can be entirely superfluous. And, in user interfaces with too many keyboard shortcuts, the excess shortcuts create cognitive load that make the most useful ones more difficult to remember.
+The first goal when designing a keyboard interface is simple, efficient, and intuitive operation with only basic keyboard navigation support. If basic operation of a keyboard interface is inefficient, attempting to compensate for fundamental design issues, such as suboptimal layout or command structure, by implementing keyboard shortcuts will not likely reduce user frustration. The practical implication of this is that, in most well-designed user interfaces, the percentage of functionality that needs to be accessible via a keyboard shortcut in order to create optimal usability is not very high. In many simple user interfaces, keyboard shortcuts can be entirely superfluous. And, in user interfaces with too many keyboard shortcuts, the excess shortcuts create cognitive load that make the most useful ones more difficult to remember.
Consider the following when deciding where to assign keyboard shortcuts:
presentation
Rolepresentation
.
+ none,
+ which serves as a synonym for presentation
.
For example, consider a tabs widget built using an HTML ul
element.
@@ -4895,11 +6401,11 @@
Browsers ignore role="presentation"
, and it therefore has no effect, if either of the following are true about the element to which it is applied:
tabindex
attribute.tabindex
attribute.aria-label
.
+ twenty-one global ARIA states and properties,
+ e.g., aria-label
.
Change history is maintained in a separate version-specific branch.