Proposed Visible label is part of accessible name
Description
This rule checks that interactive elements labeled through content have their visible label as part of their accessible name.
Applicability
This rule applies to any element for which all the following is true:
- The element has a semantic role that is a [widget][widget role] that supports name from content; and
- The element has visible text content; and
- The element has an
aria-label
oraria-labelledby
attribute.
Expectation
For the target element, the visible inner text is contained within the accessible name according to the label in name algorithm.
Background
This rule applies to elements with a [widget role][] that support name from content. This includes the following: button
, checkbox
, gridcell
, link
, menuitem
, menuitemcheckbox
, menuitemradio
, option
, radio
, searchbox
, switch
, tab
, treeitem
.
The understanding document of 2.5.3 Label in Name use the term “symbolic text characters” to refer to a type of non-text content that uses text characters as symbols, such as using “x” to mean “close”. This rule considers them as “characters expressing non-text content”. Unicode emojis are another example of characters expressing non-text content, although these are not “symbolic text characters”.
Assumptions
This rule assumes that the visible inner text is equal to the [label][https://www.w3.org/wai/wcag21/understanding/label-in-name#dfn-label], even though “label” is not precisely defined at this point in history.
This rule assumes that the visible label isn’t rearranged with CSS so that it appears to the user in a different order than it appears in the DOM.
This rule assumes that the visible label doesn’t use CSS to add whitespace where none exists in the DOM.
This rule assumes that for any word which appears in both the accessible name and the visible label, the same spelling and hyphenation is used in both places. For example: if “non-negative” is used in the accessible name and “nonnegative” is used in the visible label, that would violate this assumption. Similarly, if “color” is used in the accessible name and “colour” is used in the visible label, that would also violate this assumption.
This rule - specifically, the label in name algorithm that this rule relies on - assumes that the algorithm’s treatment of parentheses is appropriate in the given human language. “Parentheses” are also known as “round brackets”. The algorithm’s treatment of parentheses is to remove them and all characters within them. This assumption can be reworded as: content within parentheses can be ignored. This assumption is almost always true in English. It is known to be often false in other languages, such as German (where parentheses indicate dual states) and Arabic (where parentheses are often used as quotation marks). Violations of this assumption will, in real-world scenarios, more often result in a false negative for this rule rather than a false positive.
This rule assumes that all resources needed for rendering the page are properly loaded. Checking if resources are missing is out of the scope of rules. Missing resources may be rendered as text (for example, missing img
are rendered as their alt
attribute).
Accessibility Support
Implementation of Presentational Roles Conflict Resolution varies from one browser or assistive technology to another. Depending on this, some elements can have one of the applicable semantic roles and fail this rule with some technology but users of other technologies would not experience any accessibility issue.
Bibliography
- Understanding Success Criterion 2.5.3: Label in Name
- G208: Including the text of the visible label as part of the accessible name
Accessibility Requirements Mapping
2.5.3 Label in Name (Level A)
- Learn more about 2.5.3 Label in Name
- Required for conformance to WCAG 2.1 and later on level A and higher.
- Outcome mapping:
- Any
failed
outcomes: success criterion is not satisfied - All
passed
outcomes: success criterion needs further testing - An
inapplicable
outcome: success criterion needs further testing
- Any
G208: Including the text of the visible label as part of the accessible name
- Learn more about technique G208
- Not required for conformance to any W3C accessibility recommendation.
- Outcome mapping:
- Any
failed
outcomes: technique is not satisfied - All
passed
outcomes: technique needs further testing - An
inapplicable
outcome: technique needs further testing
- Any
Input Aspects
The following aspects are required in using this rule.
Test Cases
Passed
Passed Example 1
This link has visible inner text that is equal to the accessible name.
<a href="https://act-rules.github.io/" aria-label="ACT rules">ACT rules</a>
Passed Example 2
This link has visible inner text that, ignoring whitespace, is equal to the accessible name.
<a href="https://act-rules.github.io/" aria-label=" ACT rules ">ACT rules</a>
Passed Example 3
This link has visible inner text that, ignoring case, is equal to the accessible name.
<a href="https://act-rules.github.io/" aria-label="act Rules">ACT rules</a>
Passed Example 4
This button has visible inner text that is contained within the accessible name according to the label in name algorithm.
<button aria-label="Next Page in the list">Next Page</button>
Passed Example 5
This button has visible inner text that does not need to be contained within the accessible name, because the “x” text node is non-text content. Note: this would need to meet SC 1.1.1 Non text content.
<button aria-label="anything">X</button>
Passed Example 6
This button
element has the text “search” rendered as an magnifying glass icon by the font. Because the text is rendered as non-text content, the text does not need to be contained within the accessible name.
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<style>
button {
font-family: 'Material Icons';
}
</style>
<button aria-label="Find">search</button>
Passed Example 7
This button has visible inner text that, according to the label in name algorithm, is contained within the accessible name. This example shows why the label in name algorithm uses the visible inner text and not the visible text content: the <p> tags insert whitespace into the result in the former but not the latter.
<button aria-label="Hello world">
<p>Hello</p>
<p>world</p>
</button>
Passed Example 8
Similar to the previous example.
<a href="#" aria-label="Some article by John Doe"
><h6>Some article</h6>
<p>by John Doe</p></a
>
Passed Example 9
The visible inner text of this link is “ACT” (with no spaces) because of the explicit styles of display: inline
on the p
elements and the absence of whitespace between the p
elements. The cases of display: inline
and display: block
are handled by the definition of visible inner text of an element. This example shows that the definition agrees with the visual rendering done by the browser.
<a href="#" aria-label="ACT">
<p style="display: inline">A</p>
<p style="display: inline">C</p>
<p style="display: inline">T</p>
</a>
Passed Example 10
The visible inner text is “Download specification”. The words “the” and “gizmo” aren’t part of it.
<a aria-label="Download specification" href="#"
>Download <span style="visibility: hidden">the</span> <span style="display: none">gizmo</span> specification</a
>
Passed Example 11
The visible inner text is “Download specification”, which includes a space character between the two words due to the second clause of the definition of visible inner text of a text node.
<a aria-label="Download specification" href="#"
><span>Download</span><span id="space"> </span><span>specification</span></a
>
Passed Example 12
This example shows that the visible inner text isn’t always the same as the [innerText][https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute]. The visible inner text is “Download specification”. The innerText is ‘Download \ngizmo\nspecification’. This rule uses the visible inner text - not innerText.
<style>
.visually-hidden {
/* Source: https://www.tpgi.com/the-anatomy-of-visually-hidden/ */
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
</style>
<a aria-label="Download specification" href="#">Download <span class="visually-hidden">gizmo</span> specification</a>
Passed Example 13
This example shows that the label in name algorithm handles many kinds of whitespace.
<a aria-label="compose email" href="#"
>compose <br />
email</a
>
Passed Example 14
This example passes the rule because “YYYY-MM-DD” is in brackets. Text in brackets is removed by the label in name algorithm, because its not normally spoken by speech-input users.
<button aria-label="Search by date">Search by date (YYYY-MM-DD)</button>
Passed Example 15
This passes for two reasons: 1) because the ellipsis (“…”) is non-text content, and 2) because the ellipsis is neither a letter nor a digit and so is filtered out by the label in name algorithm.
<button aria-label="Next">Next…</button>
Passed Example 16
This passes because the label in name algorithm effectively ignores all punctuation and emoji, in both the visible inner text and the accessible name, as long as they don’t break up words.
<button aria-label="💡 Submit 💡">>>> ** Submit ** <<<</button>
Failed
Failed Example 1
This link has visible inner text that is very different from the accessible name.
<a href="https://act-rules.github.io/" aria-label="WCAG">ACT rules</a>
Failed Example 2
This button has visible inner text that is only partially contained within the accessible name.
<button aria-label="the full">The full label</button>
Failed Example 3
This button has visible inner text that is fully contained within the accessible name when viewed as a character-by-character substring. But that does not satisfy our label in name algorithm, which works on full words. So this fails the rule.
<a href="#" aria-label="Discover Italy">Discover It</a>
Failed Example 4
This link’s accessible name contains two tokens (according to thelabel in name algorithm) and the visible inner text contains one token. So it fails the rule.
<a aria-label="just ice" href="#">justice</a>
Failed Example 5
This link has an accessible name which contains a hyphen. The label in name algorithm breaks up words on hyphens. So it turns “non-standard” into two tokens: “non” and “standard”. So this fails the rule.
<a href="#" aria-label="non-standard">nonstandard</a>
Failed Example 6
The rule has no special handling for acronyms or initialisms.
<a aria-label="WCAG" href="#">W C A G</a>
Failed Example 7
The rule has no special handling for abbreviations.
<a aria-label="University Avenue" href="#">University Ave.</a>
Failed Example 8
This link has visible inner text with mathematical symbols and is not contained within the accessible name because the mathematical symbols are represented as English words (not digits) in the accessible name. This is explicitly mentioned in WCAG.
<a href="/" aria-label="Proof of two multiplied by two is four">Proof of 2×2=4</a>
Failed Example 9
Similar to the previous example. This rule has no special handling for converting mathematical symbols into words, or vice versa.
<button aria-label="11 times 3 equals 33">11×3=33</button>
Failed Example 10
This button’s accessible name contains the same tokens that are in the visible label. But they aren’t in the same order, so it fails the sublist check part of the label in name algorithm, and so it fails the rule.
<button aria-label="how are you"><span>you</span><span>how</span><span>are</span></button>
Failed Example 11
This button’s accessible name contains the word “the” in the middle of it, which causes the sublist check of the label in name algorithm (in particular: the “consecutive” requirement of that check) to fail. So it fails the rule.
<button aria-label="Download the specification">Download specification</button>
Failed Example 12
This link’s accessible name contains the same digits that are in the visible label, and in the same order. But they have different spaces and punctuation between them, so they are considered separate tokens. So this fails the rule.
<a aria-label="1 2 3. 4 5 6. 7 8 9 0" href="tel:1234567890">123.456.7890</a>
Failed Example 13
This rule has no special handling which tries to guess when number have the same semantic meaning. It operates on tokens only.
<a href="#2021" aria-label="20 21">2021</a>
Failed Example 14
Similar to the previous example.
<a aria-label="fibonacci: 0 1 1 2 3 5 8 13 21 34">fibonacci: 0112358132134</a>
Failed Example 15
This rule has no special handling for converting digits into words, or vice versa.
<a href="#2021" aria-label="twenty twenty-one">two thousand twenty-one</a>
Failed Example 16
(Same as above.) This rule has no special handling for converting digits into words, or vice versa.
<a aria-label="two zero two three" href="#">2 0 2 3</a>
Failed Example 17
This rule has no special handling for digits that appear next to letters with no spaces in between.
<a aria-label="1a" href="#">1</a>
Failed Example 18
The definition of visible inner text doesn’t treat text any differently if it’s excluded from the accessibility tree with aria-hidden. So this rule effectively ignores aria-hidden. So this element fails the rule.
<a aria-label="Download specification" href="#">Download <span aria-hidden="true">gizmo</span> specification</a>
Inapplicable
Inapplicable Example 1
This nav
is not a widget, so the visible inner text does not need to match the accessible name.
<nav aria-label="main nav">W3C navigation</nav>
Inapplicable Example 2
This email text field does not need to have its visible inner text match the accessible name. The content of a textfield shows its value instead of its label; it does not support name from content. The label is usually adjacent to the textfield instead.
<div>E-mail</div>
<input type="email" aria-label="E-mail" value="Contact" />
Inapplicable Example 3
This div
element does not have a widget role, so the visible inner text does not need to match the accessible name.
<div role="tooltip" aria-label="OK">Next</div>
Inapplicable Example 4
This link has no visible inner text.
<a href="https://w3.org" aria-label="W3C homepage">
<img src="/test-assets/shared/w3c-logo.png" alt="w3c logo" />
</a>
Glossary
Accessible Name
The accessible name is the programmatically determined name of a user interface element that is included in the accessibility tree.
The accessible name is calculated using the accessible name and description computation.
For native markup languages, such as HTML and SVG, additional information on how to calculate the accessible name can be found in HTML Accessibility API Mappings 1.0, Accessible Name and Description Computation (working draft) and SVG Accessibility API Mappings, Name and Description (working draft).
For more details, see examples of accessible name.
Note: As per the accessible name and description computation, each element always has an accessible name. When no accessible name is provided, the element will nonetheless be assigned an empty (""
) one.
Note: As per the accessible name and description computation, accessible names are flat string trimmed of leading and trailing whitespace. Notably, it is not possible for a non-empty accessible name to be composed only of whitespace since these must be trimmed.
Explicit Semantic Role
The explicit semantic role of an element is determined by its role attribute (if any).
The role attribute takes a list of tokens. The explicit semantic role is the first valid role in this list. The valid roles are all non-abstract roles from WAI-ARIA Specifications. If the element has no role attribute, or if it has one with no valid role, then this element has no explicit semantic role.
Other roles may be added as they become available. Not all roles will be supported in all assistive technologies. Testers are encouraged to adjust which roles are allowed according to the accessibility support base line. For the purposes of executing test cases in all rules, it should be assumed that all roles are supported by assistive technologies so that none of the roles fail due to lack of accessibility support.
Focusable
An element is focusable if one or both of the following are true:
- the element is part of sequential focus navigation; or
- the element has a tabindex value that is not null.
Exception: Elements that lose focus and do not regain focus during a period of up to 1 second after gaining focus, without the user interacting with the page the element is on, are not considered focusable.
Notes:
- The 1 second time span is an arbitrary limit which is not included in WCAG. Given that scripts can manage the focus state of elements, testing the focusability of an element consistently would be impractical without a time limit.
- The tabindex value of an element is the value of the tabindex attribute parsed using the rules for parsing integers. For the tabindex value to be different from null, it needs to be parsed without errors.
Implicit Semantic Role
The implicit semantic role of an element is a pre-defined value given by the host language which depends on the element and its ancestors.
Implicit roles for HTML and SVG, are documented in the HTML accessibility API mappings (working draft) and the SVG accessibility API mappings (working draft).
Included in the accessibility tree
Elements included in the accessibility tree of platform specific accessibility APIs are exposed to assistive technologies. This allows users of assistive technology to access the elements in a way that meets the requirements of the individual user.
The general rules for when elements are included in the accessibility tree are defined in the core accessibility API mappings. For native markup languages, such as HTML and SVG, additional rules for when elements are included in the accessibility tree can be found in the HTML accessibility API mappings (working draft) and the SVG accessibility API mappings (working draft).
For more details, see examples of included in the accessibility tree.
Programmatically hidden elements are removed from the accessibility tree. However, some browsers will leave focusable elements with an aria-hidden
attribute set to true
in the accessibility tree. Because they are hidden, these elements are considered not included in the accessibility tree. This may cause confusion for users of assistive technologies because they may still be able to interact with these focusable elements using sequential keyboard navigation, even though the element should not be included in the accessibility tree.
Label in Name Algorithm
To check whether an element has its label contained in its name, follow this algorithm:
Let ‘label’ be the visible inner text of the target element. Let ‘name’ be the accessible name of the target element. Both ‘label’ and ‘name’ are strings.
Sub-algorithm to tokenize a string:
- Do Unicode case folding on the string then convert it to normalization form KD.
- For each character that either a) represents non-text content, or b) isn’t a letter or a digit: replace that character with a space character.
- For a) Judgment of “non-text” probably can’t be fully automated. For example: “X” for “close” probably can be automated, but presumably there are more cases than this.
- For b) Use the Unicode classes Letter, Mark, and “Number, Decimal Digit [Nd]”. (This will exclude hyphens, punctuation, emoji, and more.)
- Remove all characters that are within parentheses (AKA round brackets).
- Ignore square brackets and braces.
- Split the string into a list of strings, one string per word, according to the word segmentation rules for the inherited programmatic language.
- This ‘split’ operation must:
- Effectively remove leading and trailing whitespace.
- If the input string contains nothing but whitespace before this operation: return an empty list.
- In English and most other European languages, a greedy whitespace regular expression will accomplish this. In languages such as Thai, Chinese, and Japanese, it won’t.
- A consequence of using the ACT definition of whitespace here is that all kinds of whitespace are covered. That includes the Unicode code point U+00A0 - the “No-Break Space” - which can be represented by the HTML named character reference
.
- This ‘split’ operation must:
Then do the check: is the tokenized ‘label’ a sublist of the tokenized ‘name’?
- This ‘sublist’ check has these properties:
- It checks whether elements are consecutive or not. That is: it checks for a substring, in the computer science sense of the term. Not a subsequence.
- An empty list is a sublist of any list.
If the answer is “yes” (that is: the tokenized ‘label’ is a sublist of the tokenized ‘name’), then this algorithm returns “is contained”. Otherwise, it returns “is not contained”.
Marked as decorative
An element is marked as decorative if one or more of the following conditions is true:
- it has an explicit role of
none
orpresentation
; or - it is an
img
element with analt
attribute whose value is the empty string (alt=""
), and with no explicit role.
Elements are marked as decorative as a way to convey the intention of the author that they are pure decoration. It is different from the element actually being pure decoration as authors may make mistakes. It is different from the element being effectively ignored by assistive technologies as rules such as presentational roles conflict resolution may overwrite this intention.
Elements can also be ignored by assistive technologies if they are programmatically hidden. This is different from marking the element as decorative and does not convey the same intention. Notably, being programmatically hidden may change as users interact with the page (showing and hiding elements) while being marked as decorative should stay the same through all states of the page.
Outcome
A conclusion that comes from evaluating an ACT Rule on a test subject or one of its constituent test target. An outcome can be one of the five following types:
- Inapplicable: No part of the test subject matches the applicability
- Passed: A test target meets all expectations
- Failed: A test target does not meet all expectations
- cantTell: Whether the rule is applicable, or not all expectations were met could not be fully determined by the tester.
- Untested: The tester has not attempted to evaluate the test subject.
Note: A rule has one passed
or failed
outcome for every test target. When a tester evaluates a test target it can also be reported as cantTell
if the rule cannot be tested in its entirety. For example, when applicability was automated, but the expectations have to be evaluated manually.
When there are no test targets the rule has one inapplicable
outcome. If the tester is unable to determine whether there are test targets there will be one cantTell
outcome. And when no evaluation has occurred the test target has one untested outcome. This means that each test subject always has one or more outcomes.
Outcomes used in ACT Rules can be expressed using the outcome property of the [EARL10-Schema][].
Programmatically Hidden
An HTML element is programmatically hidden if either it has a computed CSS property visibility
whose value is not visible
; or at least one of the following is true for any of its inclusive ancestors in the flat tree:
- has a computed CSS property
display
ofnone
; or - has an
aria-hidden
attribute set totrue
Note: Contrary to the other conditions, the visibility
CSS property may be reverted by descendants.
Note: The HTML standard suggests setting the CSS display
property to none
for elements with the hidden
attribute. While not required by HTML, all modern browsers follow this suggestion. Because of this the hidden
attribute is not used in this definition. In browsers that use this suggestion, overriding the CSS display
property can reveal elements with the hidden
attribute.
Semantic Role
The semantic role of an element is determined by the first of these cases that applies:
- Conflict If the element is marked as decorative, but the element is included in the accessibility tree; or would be included in the accessibility tree when it is not programmatically hidden, then its semantic role is its implicit role.
- Explicit If the element has an explicit role, then its semantic role is its explicit role.
- Implicit The semantic role of the element is its implicit role.
This definition can be used in expressions such as “semantic button
” meaning any element with a semantic role of button
.
Visible
Content perceivable through sight.
Content is considered visible if making it fully transparent would result in a difference in the pixels rendered for any part of the document that is currently within the viewport or can be brought into the viewport via scrolling.
For more details, see examples of visible.
Visible Inner Text
(The “visible inner text” defined here is similar to, but not the same as, visible text content and [innerText][https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute].)
The visible inner text of a node depends on the kind of node.
The visible inner text of a text node is:
- if the text node is visible, its visible inner text is its data with whitespace normalized by replacing contiguous whitespace with the string
" "
(a single ASCII space character); - if the text node is not visible, is rendered, and contains only whitespace, its visible inner text is the string
" "
(a single ASCII space character); - otherwise, the visible inner text of the text node is the empty string (
""
).
The visible inner text of an element is:
- if the element is not rendered, its visible inner text is the empty string (
""
); - if the element is rendered and not visible and has a bounding box which has width greater than 0, its visible inner text is an ASCII space character (
" "
); - if the element is rendered and not visible and has a bounding box which has width of 0, its visible inner text is the empty string (
""
); - if the element is a
<br>
element, its visible inner text is a newline character ("\n"
); - if the computed
display
property of the element has an outer display type ofblock
, or an inner display type oftable-caption
, the visible inner text of the element is the concatenation of a newline character ("\n"
) plus the visible inner text of its children (in tree order in the flat tree) plus a newline character ("\n"
); - if the computed
display
property of the element has an inner display type oftable-cell
ortable-row
, the visible inner text of the element is the concatenation of an ASCII space character (" "
) plus the visible inner text of its children (in tree order in the flat tree) plus an ASCII space character (" "
); - otherwise, the visible inner text of the element is the concatenation of the visible inner text of its children (in tree order in the flat tree).
The visible inner text of any other node is the concatenation of the visible inner text of its children (in tree order in the flat tree).
Visible Text Content
The visible text content of an element is a set of all visible text nodes that are descendants in the flat tree of this element. (This is similar to, but not the same as, visible inner text.)
WAI-ARIA specifications
The WAI ARIA Specifications group both the WAI ARIA W3C Recommendation and ARIA modules, namely:
- Accessible Rich Internet Applications (WAI-ARIA) 1.2
- WAI-ARIA Graphics Module 1.0
- Digital Publishing WAI-ARIA Module 1.0
Note: depending on the type of content being evaluated, part of the specifications might be irrelevant and should be ignored.
Whitespace
Whitespace are characters that have the Unicode “White_Space” property in the Unicode properties list.
This includes:
- all characters in the Unicode Separator categories, and
-
the following characters in the Other, Control category:
- Character tabulation (U+0009)
- Line Feed (LF) (U+000A)
- Line Tabulation (U+000B)
- Form Feed (FF) (U+000C)
- Carriage Return (CR) (U+000D)
- Next Line (NEL) (U+0085)
whitespace: #whitespace ‘Definition of whitespace’ [widget role]: https://www.w3.org/TR/wai-aria-1.2/#widget_roles ‘Definition of Widget role’
Rule Versions
This is the first version of this ACT rule.
Implementations
This section is not part of the official rule. It is populated dynamically and not accounted for in the change history or the last modified date.