简体   繁体   English

aria-label 可以用于什么?

[英]What can aria-label be used on?

What exactly can aria-label be used on? aria-label到底可以用于什么?

I have found documentation that shows it can be used on interactive items (such as <button> for example), but can it be used on any of the following: <p> , <span> , <li> or <abbr> ?我发现文档表明它可以用于交互式项目(例如<button> ),但它可以用于以下任何一项: <p><span><li><abbr>吗?

I am trying to have particular words and abbreviations within a paragraph, read out as something specific (eg: Aussies read out as "Ozzies" instead of "Ossies" or "NSW" read out as "New South Wales")我试图在段落中包含特定的单词和缩写,作为特定的东西读出(例如:澳大利亚人读出为“Ozzies”而不是“Ossies”或“NSW”读出为“新南威尔士州”)

Testing in Microsoft Edge, Google Chrome, Mozilla Firefox (all Windows 10) and iPhone Safari (iOS)在 Microsoft Edge、Google Chrome、Mozilla Firefox(所有 Windows 10)和 iPhone Safari (iOS) 中进行测试

You should generally not use aria-label on static content.您通常不应在静态内容上使用aria-label It's only intended to be used on interactive elements and some sectioning elements.它仅用于交互式元素和一些分段元素。

https://www.w3.org/TR/using-aria/#practical-support-aria-label-aria-labelledby-and-aria-describedby https://www.w3.org/TR/using-aria/#practical-support-aria-label-aria-labelledby-and-aria- describeby

  • aria-labelledby and aria-describedby are robustly supported for interactive content elements such as links and form controls including the many input types. aria-labelledbyaria-describedby得到了交互式内容元素的强大支持,例如链接和表单控件,包括许多输入类型。

  • For most assistive technology it's fine to use aria-label or aria-labelledby on the <nav> , and <main> elements but not on <footer> , <section> , <article> , or <header> .对于大多数辅助技术,可以在<nav><main>元素上使用aria-labelaria-labelledby ,但不能在<footer><section><article><header>上使用。

  • There is mixed support for aria-label or aria-labelledby on <aside> . <aside>上对aria-labelaria-labelledby有混合支持。

  • Talkback on Android overrides the content of all landmarks with aria-label or aria-labelledby . Android 上的 Talkback 使用aria-labelaria-labelledby覆盖所有地标的内容。

  • Its fine to use aria-label or aria-labelledby on div elements with role=navigation , role=search , role=main , JAWS doesn't support them on role=banner , role=complementary , role=contentinfo .在具有role=navigationrole=searchrole=maindiv元素上使用aria-labelaria-labelledby很好,JAWS 在role=bannerrole=complementaryrole=contentinfo上不支持它们。 NVDA, VoiceOver, and Talkback are OK NVDA、VoiceOver 和 Talkback 都可以

  • aria-label , aria-labelledby and aria-describedby work well on table , th and td elements with a few exceptions for NVDA, VoiceOver on iOS, and Talkback discussed in next section. aria-labelaria-labelledbyaria-describedbytablethtd元素上运行良好,但 NVDA、iOS 上的 VoiceOver 和下一节讨论的 Talkback 有一些例外。

  • Don't use aria-label or aria-labelledby on any heading elements because it overrides them on NVDA, VoiceOver and Talkback.不要在任何标题元素上使用aria-labelaria-labelledby ,因为它会在 NVDA、VoiceOver 和 Talkback 上覆盖它们。 JAWS ignores them. JAWS 会忽略它们。

  • Don't use aria-label or aria-labelledby on any other non-interactive content such as p , legend , li , or ul , because it is ignored.不要在任何其他非交互式内容上使用aria-labelaria-labelledby ,例如plegendliul ,因为它会被忽略。

  • Don't use aria-label or aria-labelledby on a span or div unless its given a role .不要在spandiv上使用aria-labelaria-labelledby ,除非给定了role When aria-label or aria-labelledby are on interactive roles (such as a link or button) or an img role, they override the contents of the div or span .aria-labelaria-labelledby处于交互式角色(例如链接或按钮)或 img 角色时,它们会覆盖divspan的内容。 Other roles besides Landmarks (discussed above) are ignored.除了地标(上面讨论过)之外的其他角色被忽略。

Keep in mind that the above guidance was written in 2018, and support has likely improved among some browsers, but the advice above is still safe, and I would recommend mostly following it.请记住,上述指南是在 2018 年编写的,并且某些浏览器的支持可能有所改善,但上述建议仍然是安全的,我建议您主要遵循它。

Thanks to brennanyoung for passing along this great article from Steve Faulkner: https://html5accessibility.com/stuff/2020/11/07/not-so-short-note-on-aria-label-usage-big-table-edition/感谢 brennanyoung 传递 Steve Faulkner 的这篇精彩文章: https ://html5accessibility.com/stuff/2020/11/07/not-so-short-note-on-aria-label-usage-big-table-edition /

It's worth mentioning that the above test results are more recent than the advice given by W3C at the beginning of my post, and it does contradict the W3C advice in some places.值得一提的是,上面的测试结果比我文章开头的 W3C 给出的建议更新,并且在某些地方确实与 W3C 的建议相矛盾。

Additional Resources:其他资源:

Attributes aria-label and aria-labelledby are typically used and correctly recognized only on interactive elements such a buttons, form fields, links, etc. They usually don't work, ie not read or shown, when they are used on non-interactive elements such as <p>, <div>, <li> . aria-label 和 aria-labelledby 属性通常仅在交互式元素(如按钮、表单字段、链接等)上使用和正确识别。当它们用于非交互式时,它们通常不起作用,即无法读取或显示<p>, <div>, <li>等元素。

You can use aria-label or aria-labelledby on a <p>, <li> , but it will work only if it's interactive.您可以在<p>, <li>上使用 aria-label 或 aria-labelledby ,但它只有在交互式时才有效。 The definition of interactive is quite simple: it means something you can interact with.交互的定义很简单:它意味着你可以与之交互的东西。 More technically, it basically means focusable.从技术上讲,它基本上意味着可聚焦。

Note that with some browsers and/or screen readers, aria-label on elements that aren't naturally focusable may only work when navigating in form mode but not in browse mode.请注意,对于某些浏览器和/或屏幕阅读器,无法自然聚焦的元素上的 aria-label 可能仅在以表单模式导航时有效,而在浏览模式下无效。 BY naturally focusable, I mean elements that don't need an explicit tabindex to be interactive.通过自然可聚焦,我的意思是不需要显式 tabindex 即可交互的元素。

The element <abbr> is a special case.元素<abbr>是一个特例。 The expanded meaning must be present in the title attribute and not aria-label.扩展的含义必须出现在 title 属性中,而不是 aria-label 中。

It's most likely an attribute to help people with disabilities and the elderly.这很可能是帮助残疾人和老年人的一个属性。 (eg screen readers) attach a label to an otherwise anonymous HTML element. (例如屏幕阅读器)将标签附加到其他匿名 HTML 元素。

Usually search input field does not have visual label (thanks to designers).通常搜索输入字段没有视觉标签(感谢设计师)。 aria-label can be used to communicate the label of control to screen reader users. aria-label 可用于将控件标签传达给屏幕阅读器用户。

When user focus on both button(by pressing tab) with area label — you can hear focusing on first x button — will tell you only x button but in case of second x button .. you will hear back to the page button only..当用户关注带有区域标签的两个按钮(通过按选项卡)时——你可以听到关注第一个 x 按钮——只会告诉你 x 按钮,但如果是第二个 x 按钮..你只会听到返回到页面按钮..

<button title="Close"> X </button>


<button aria-label="Back to the page" title="Close" > X </button>

i hope it helps.我希望它有帮助。

you can read further information here https://www.aditus.io/aria/aria-label/您可以在此处阅读更多信息https://www.aditus.io/aria/aria-label/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM