DEV Community

Kashif Raza
Kashif Raza

Posted on

Using aria-labelledby

Using aria-labelledby to provide a text alternative for non-text content
The purpose of this technique is to provide a short description for an element that can be read by assistive technologies (AT) by using the aria-labelledby attribute. The aria-labelledby attribute associates an element with text that is visible elsewhere on the page by using an ID reference value that matches the ID attribute of the labeling element. Assistive technology such as screen readers use the text of the element identified by the value of the aria-labelledby attribute as the text alternative for the element with the attribute.

Note: When using aria-labelledby attribute on an img element, the absence of an alt attribute will cause validation failures for HTML 4 and earlier and XHTML. If alt is provided, it must contain the same text as the aria-labelledby target. Do not use alt="", which would cause some assistive techology to ignore the image completely.

< img src="sunflowers.jpg" aria-labelledby="flower_id" >


< span id="flower_id">Van Gogh's oil painting of sunflowers< / span >
hangs in Amsterdam's Van Gogh museum.

Top comments (0)