Using the aria-hidden attribute - Accessibility 编辑
Draft
This page is not complete.
This technique demonstrates how to use the aria-hidden
attribute. The aria-hidden
attribute can either expose or hide non-interactive content from the accessibility API.
Description
Adding aria-hidden="true"
to an element removes that element and all of its children from the accessibility tree. This can improve the experience for assistive technology users by hiding:
- purely decorative content, such as icons or images
- duplicated content, such as repeated text
- offscreen or collapsed content, such as menus
According to the fourth rule of ARIA, aria-hidden="true"
should not be used on a focusable element. Additionally, since this attribute is inherited by an element's children, it should not be added onto the parent or ancestor of a focusable element.
Using aria-hidden="false"
will not re-expose the element to assistive technology if any of its parents specify aria-hidden="true".
WAI-ARIA Authoring Practices 1.1 notes that aria-hidden="false"
currently behaves inconsistently across browsers.
Deciding between aria-hidden="true", role="presentation", and role="none"
On the surface, the aria-hidden="true"
, role="presentation"
, and role="none"
attributes seem similar because they:
- hide content from assistive technology
- cannot be used on a focusable element
- cannot be used on the parent of an interactive element
Despite these similarities, the intent behind each attribute is different.
aria-hidden="true"
will remove the entire element from the accessibility API.role="presentation"
androle="none"
will remove the semantic meaning of an element while still exposing it to assistive technology.
Values
false
- (default) The element is exposed to the accessibility API.
true
- The element is not exposed to the accessibility API.
undefined
- (default) The user agent determines if the element is exposed to or hidden from the accessibility API.
Examples
In the example below, the paragraph is not exposed to the accessibility API (e.g. would not be read aloud by a screen reader).
<p aria-hidden="true">
Some things are better left unsaid.
</p>
Children elements can be omitted from accessibility APIs:
<p>
This is not hidden <span aria-hidden="true">but this is</span>!
</p>
Accessibility concerns
Best practices
aria-hidden="true"
should not be added when:
- the HTML
hidden
attribute is present - the element or the element's ancestor is hidden with
display: none
- The element or the element's ancestor is hidden with
visibility: hidden
In all three scenarios, the attribute is unnecessary to add because the element has already been removed from the accessibility tree.
Specifications
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论