New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(aria-label): Improve page for clarity #32688
Conversation
Preview URLs External URLs (1)URL:
(comment last updated: 2024-03-27 18:53:42) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
several very minor suggestions
@@ -12,11 +12,11 @@ Accessible names convey the purpose or intent of the element. This helps users u | |||
|
|||
Depending on the element and the HTML markup, the value of the accessible name may be derived from visible (e.g., the text within {{HTMLElement("figcaption")}}) or invisible (e.g., the `aria-label` attribute set on an element) content, or a combination of both. How an element's accessible name is determined is based on the [accessible name calculation](https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/#name_calculation), which is different for different elements. | |||
|
|||
It is best to use visible text as the accessible names. Many elements, including {{HTMLElement("a")}}, {{HTMLElement("td")}} and {{HTMLElement("button")}}, get their name from their contents. For example, given `<a href="foo.html">Bar</a>`, the accessible name is "Bar." | |||
It is best to use visible text as the accessible name. Many elements, including {{HTMLElement("a")}}, {{HTMLElement("td")}} and {{HTMLElement("button")}}, get their accessible names from their contents. For example, given `<a href="foo.html">Bar</a>`, the accessible name of this `<a>` element is "Bar." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is best to use visible text as the accessible name. Many elements, including {{HTMLElement("a")}}, {{HTMLElement("td")}} and {{HTMLElement("button")}}, get their accessible names from their contents. For example, given `<a href="foo.html">Bar</a>`, the accessible name of this `<a>` element is "Bar." | |
It is best to use visible text as the accessible name. Many elements, including {{HTMLElement("a")}}, {{HTMLElement("td")}} and {{HTMLElement("button")}}, get their accessible name from their contents. For example, given `<a href="foo.html">Bar</a>`, the accessible name of this `<a>` element is "Bar." |
the plural made it sound like an element can have more than one accessible name. It is correct to use "names", but "name" is also ok, and less likely to create confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you estelle. i was feeling very iffy about these updates - so i'm glad you share my concern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably the right fix here would be to also make "content" singular:
It is best to use visible text as the accessible name. Many elements, including {{HTMLElement("a")}}, {{HTMLElement("td")}} and {{HTMLElement("button")}}, get their accessible name from their content.
|
||
Other elements get their accessible name from the content of associated elements. For some parent elements, like {{HTMLElement("fieldset")}}, {{HTMLElement("table")}}, and {{HTMLElement("figure")}}, if those elements contain a descendant {{HTMLElement("fieldset")}}, {{HTMLElement("caption")}}, or {{HTMLElement("figcaption")}}, respectively, the association is automatic. For some other elements, like {{HTMLElement("textarea")}} and {{HTMLElement("input")}}, the accessible name also comes from an associated element, the {{HTMLElement("label")}} element, but that association has to explicitly set with a `for` attribute value on the `<label>` that matches the form control's `id`. | ||
Other elements get their accessible names from the content of associated elements. If some parent elements such as {{HTMLElement("fieldset")}}, {{HTMLElement("table")}}, and {{HTMLElement("figure")}} contain a descendant {{HTMLElement("fieldset")}}, {{HTMLElement("caption")}}, or {{HTMLElement("figcaption")}} element, respectively, the association is automatic. For form elements like {{HTMLElement("textarea")}} and {{HTMLElement("input")}}, the accessible name comes from the associated {{HTMLElement("label")}} element; the association in this case has to be explicitly defined by setting the `for` attribute in the `<label>` element to match the `id` of the form control. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other elements get their accessible names from the content of associated elements. If some parent elements such as {{HTMLElement("fieldset")}}, {{HTMLElement("table")}}, and {{HTMLElement("figure")}} contain a descendant {{HTMLElement("fieldset")}}, {{HTMLElement("caption")}}, or {{HTMLElement("figcaption")}} element, respectively, the association is automatic. For form elements like {{HTMLElement("textarea")}} and {{HTMLElement("input")}}, the accessible name comes from the associated {{HTMLElement("label")}} element; the association in this case has to be explicitly defined by setting the `for` attribute in the `<label>` element to match the `id` of the form control. | |
Other elements get their accessible name from the content of associated elements. If some parent elements such as {{HTMLElement("fieldset")}}, {{HTMLElement("table")}}, and {{HTMLElement("figure")}} contain a descendant {{HTMLElement("fieldset")}}, {{HTMLElement("caption")}}, or {{HTMLElement("figcaption")}} element, respectively, the association is automatic. For form elements like {{HTMLElement("textarea")}} and {{HTMLElement("input")}}, the accessible name comes from the associated {{HTMLElement("label")}} element; the association in this case has to be explicitly defined by setting the `for` attribute in the `<label>` element to match the `id` of the form control, unless the association is implicit as is the case when the form control is nested within the `<label>`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would remove the example of figure > figcaption. since (though this is taking a while to get full implementation) figcaption will not provide a name to figure in the future. this was generally considered too noisy and redundant, especially since figcaptions can contain structured content which would not have their semantics communicated in the flattened text string that becomes the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, both!
Fixing the last sentence as:
The association needs to be explicitly defined by setting the
for
attribute in the<label>
element to match the form element'sid
. Alternatively, an implicit association is created when the form control is directly nested within the<label>
element.
@scottaohara thanks for the insights into the future direction of figure > figcaption regarding accessible name. I've removed their mention.
files/en-us/web/accessibility/aria/attributes/aria-label/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/accessibility/aria/attributes/aria-label/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/accessibility/aria/attributes/aria-label/index.md
Outdated
Show resolved
Hide resolved
|
||
> **Note:** The `aria-label` is only "visible" to assistive technologies. If the information is important enough to add for AT users, consider making it visible for all users. | ||
- Not all elements can be given an accessible name. Neither `aria-label` nor `aria-labelledby` should be used with non-interactive elements, inline structural roles such as with `code`, `term`, and `emphasis`, and roles not be mapped to the accessibility API, including `presentation`, `none`, and `hidden`. The `aria-label` attribute is intended for interactive elements only, including links, videos, form controls, and those with [landmark roles](/en-US/docs/Web/Accessibility/ARIA/Roles#3._landmark_roles) or [widget roles](/en-US/docs/Web/Accessibility/ARIA/Roles#2._widget_roles); `aria-label` provides an accessible name when no visible label exists in the DOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Not all elements can be given an accessible name. Neither `aria-label` nor `aria-labelledby` should be used with non-interactive elements, inline structural roles such as with `code`, `term`, and `emphasis`, and roles not be mapped to the accessibility API, including `presentation`, `none`, and `hidden`. The `aria-label` attribute is intended for interactive elements only, including links, videos, form controls, and those with [landmark roles](/en-US/docs/Web/Accessibility/ARIA/Roles#3._landmark_roles) or [widget roles](/en-US/docs/Web/Accessibility/ARIA/Roles#2._widget_roles); `aria-label` provides an accessible name when no visible label exists in the DOM. | |
- Not all elements can be given an accessible name. Neither `aria-label` nor `aria-labelledby` should be used with non-interactive elements, inline structural roles such as with `code`, `term`, and `emphasis`, and roles not mapped to the accessibility API, including `presentation`, `none`, and `hidden`. The `aria-label` attribute is intended for interactive elements only, including links, videos, form controls, and those with [landmark roles](/en-US/docs/Web/Accessibility/ARIA/Roles#3._landmark_roles) or [widget roles](/en-US/docs/Web/Accessibility/ARIA/Roles#2._widget_roles); `aria-label` provides an accessible name when no visible label exists in the DOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't entirely true. it's not just interactive elements that aria-label or aria-labelledby can be used with. I realize this wasn't a change made in this PR, but since this PR is open, this information should be corrected. There are various non-interactive elemetns which can benefit from having an aria-label/labelledby name, if one can't use the native features to provide one (e.g., tables, fieldsets)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scottaohara I'm glad you mentioned this because I started looking at this page precisely because of this issue raised here: The documentation for aria-label mentions that this is for interactive elements only, but this doesn't seem right #31739
There are two instances on the page that mention that aria-label
should be used for interactive elements only.
- I'm removing this note in the Associated roles section:
Note: The
aria-label
attribute is intended for interactive elements only. When placed on non-interactive elements, such as those listed above, it may not be read or may confuse your users as a non-interactive element that acts like an interactive one.
- I'm updating the above point as follows (removing reference to non-interactive elements, removing
hidden
):
- Not all elements can be given an accessible name. Neither
aria-label
noraria-labelledby
should be used with inline structural roles such ascode
,term
, andemphasis
, and roles not mapped to the accessibility API, includingnone
. Thearia-label
attribute is intended for elements including links, videos, form controls, and those with landmark roles or widget roles;aria-label
provides an accessible name when no visible label exists in the DOM.
- Updating the list in the Associated roles section as per https://w3c.github.io/aria/#namefromprohibited.
definition
was missing.
files/en-us/web/accessibility/aria/attributes/aria-label/index.md
Outdated
Show resolved
Hide resolved
@@ -12,11 +12,11 @@ Accessible names convey the purpose or intent of the element. This helps users u | |||
|
|||
Depending on the element and the HTML markup, the value of the accessible name may be derived from visible (e.g., the text within {{HTMLElement("figcaption")}}) or invisible (e.g., the `aria-label` attribute set on an element) content, or a combination of both. How an element's accessible name is determined is based on the [accessible name calculation](https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/#name_calculation), which is different for different elements. | |||
|
|||
It is best to use visible text as the accessible names. Many elements, including {{HTMLElement("a")}}, {{HTMLElement("td")}} and {{HTMLElement("button")}}, get their name from their contents. For example, given `<a href="foo.html">Bar</a>`, the accessible name is "Bar." | |||
It is best to use visible text as the accessible name. Many elements, including {{HTMLElement("a")}}, {{HTMLElement("td")}} and {{HTMLElement("button")}}, get their accessible names from their contents. For example, given `<a href="foo.html">Bar</a>`, the accessible name of this `<a>` element is "Bar." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you estelle. i was feeling very iffy about these updates - so i'm glad you share my concern
|
||
Other elements get their accessible name from the content of associated elements. For some parent elements, like {{HTMLElement("fieldset")}}, {{HTMLElement("table")}}, and {{HTMLElement("figure")}}, if those elements contain a descendant {{HTMLElement("fieldset")}}, {{HTMLElement("caption")}}, or {{HTMLElement("figcaption")}}, respectively, the association is automatic. For some other elements, like {{HTMLElement("textarea")}} and {{HTMLElement("input")}}, the accessible name also comes from an associated element, the {{HTMLElement("label")}} element, but that association has to explicitly set with a `for` attribute value on the `<label>` that matches the form control's `id`. | ||
Other elements get their accessible names from the content of associated elements. If some parent elements such as {{HTMLElement("fieldset")}}, {{HTMLElement("table")}}, and {{HTMLElement("figure")}} contain a descendant {{HTMLElement("fieldset")}}, {{HTMLElement("caption")}}, or {{HTMLElement("figcaption")}} element, respectively, the association is automatic. For form elements like {{HTMLElement("textarea")}} and {{HTMLElement("input")}}, the accessible name comes from the associated {{HTMLElement("label")}} element; the association in this case has to be explicitly defined by setting the `for` attribute in the `<label>` element to match the `id` of the form control. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would remove the example of figure > figcaption. since (though this is taking a while to get full implementation) figcaption will not provide a name to figure in the future. this was generally considered too noisy and redundant, especially since figcaptions can contain structured content which would not have their semantics communicated in the flattened text string that becomes the name.
|
||
> **Note:** The `aria-label` is only "visible" to assistive technologies. If the information is important enough to add for AT users, consider making it visible for all users. | ||
- Not all elements can be given an accessible name. Neither `aria-label` nor `aria-labelledby` should be used with non-interactive elements, inline structural roles such as with `code`, `term`, and `emphasis`, and roles not be mapped to the accessibility API, including `presentation`, `none`, and `hidden`. The `aria-label` attribute is intended for interactive elements only, including links, videos, form controls, and those with [landmark roles](/en-US/docs/Web/Accessibility/ARIA/Roles#3._landmark_roles) or [widget roles](/en-US/docs/Web/Accessibility/ARIA/Roles#2._widget_roles); `aria-label` provides an accessible name when no visible label exists in the DOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't entirely true. it's not just interactive elements that aria-label or aria-labelledby can be used with. I realize this wasn't a change made in this PR, but since this PR is open, this information should be corrected. There are various non-interactive elemetns which can benefit from having an aria-label/labelledby name, if one can't use the native features to provide one (e.g., tables, fieldsets)
Thank you, @estelle and @scottaohara, for your insightful reviews and suggestions! I've addressed all your comments. I'd appreciate if you could take another look. Scott, your feedback about the use of (I've updated the PR description to include a reference to the issue that initiated this PR.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some text simplification suggestions
files/en-us/web/accessibility/aria/attributes/aria-label/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/accessibility/aria/attributes/aria-label/index.md
Outdated
Show resolved
Hide resolved
Thanks @estelle and @scottaohara for the reviews! |
Description
Glossary page: Accessible name
Attribute: aria-label
Motivation
To improve readability, clarity, and organization
Related issues and pull requests
Update: Partially addresses #31739