Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I reference multiple elements using aria-describedby?

If I have two elements that together describe one element, can I use two ids on aria-describedby attribute like this?

<div id="description-1"></div>
<div id="description-2"></div>
<div aria-describedby="description-1 description-2"></div>
like image 556
Moaaz Bhnas Avatar asked Nov 20 '18 17:11

Moaaz Bhnas


People also ask

Can aria-Labelledby have multiple IDs?

Like aria-describedby , aria-labelledby can accept multiple ids to point to other elements of the page using a space separated list. This capability makes aria-labelledby especially useful in situations where sighted users use information from the surrounding context to identify a control.

What is aria-Describedby used for?

The aria-describedby attribute lists the id s of the elements that describe the object. It is used to establish a relationship between widgets or groups and the text that describes them.

What is the difference between aria-Labelledby and aria-Describedby?

aria-labelledby should reference brief text that provides the element with an accessible name. aria-describedby is used to reference longer content that provides a description.

Do aria-Describedby attributes provide additional information?

Generally speaking the attribute aria-describedby provides the screen reader with the additional information to be announced along the content of the element (not the only but the most common use-case).


2 Answers

Yes. The aria-describedby (and aria-labelledby) attribute expects an ID reference list as it's value. Multiple IDs can be provided, separated by spaces. When you associate multiple elements in this way, they are concatenated into a single description string.

A few things to watch out for:

  • Punctuation. If the 2 referenced elements are intended as separate sentences, it helps to put include a full stop (period) so that screen readers can announce it more naturally. Alternatively, you can use multiple references to build up a sentence. It depends on your scenario.
  • aria-describedby isn't effective on all elements. In your example the attribute is on a div element, which generally doesn't work. It works better when used on interactive elements and landmark regions. See Short note on aria-label, aria-labelledby, and aria-describedby for guidance.
  • The referenced elements will form part of the accessible description regardless of whether they are visible. Be careful if associating error messages this way. See Hidden or visible – makes no difference for guidance here.

For further details, see the Accessible Name and Description Computation rules in HTML Accessibility API Mappings 1.0.

like image 100
andrewmacpherson Avatar answered Apr 28 '23 08:04

andrewmacpherson


Absolutely.

https://www.w3.org/TR/wai-aria/#aria-describedby

Identifies the element (or elements) that describes the object

like image 24
slugolicious Avatar answered Apr 28 '23 09:04

slugolicious