Accessibility Settings

ARIA label and description

ARIA labels

Information
Generic elements, such as div and span, must not have an aria-label or aria-labelledby.

aria-label

Without the use of an ARIA label, the text content of an element is used to represent said element by a screen reader.

Without further modification, all elements (text, buttons, links, inputs, and more) will be read by the screen reader based on their text while also announcing the type of interaction if they are interactive. This, of course, can be great if your text content already provides all the details necessary to understand it, but our buttons are rather bare-bones.

Since the text "Image:" will not be announced when manually navigating between the buttons, as with tab navigation, the buttons are only known as "Save", "Save As", and "Load" to people reliant on screen readers.

Image:

To make them more accessible, we can simply add an ARIA label to each of the buttons with a more descriptive name, like "Save image". This way, any navigation between the buttons will result in the screen reader announcing the buttons with their intended purpose. It is very helpful when different parts of your website provide similar actions with the same visible text but operate in different context, like "Save image" in the image section and "Save audio" in the sound section of a video editing tool.

Image:
Information
ARIA labels should always contain all word from the visible text when text is set.
Do not create labels with entirely different content than visible text, rather expand on the text.

aria-labelledby

The aria-labelledby attribute has similar use as aria-label. Rather than specifying an explicit name for an element, it references another element (or multiple elements) containing the name.

Toggle darkmode

Keep in mind, this functionality can easily be provided with native label elements

As stated, it is possible to use multiple elements in the labelledby attribute. Simply write your target element IDs separated by a whitespace. The advantage of this is the ability to change individual parts of the message, like an item count, using JavaScript without rewriting the entire label.

It can be desirable to hide the elements used as labelledby to prevent unintended narration of the content.

ARIA Descriptions

aria-description

ARIA description is in the draft for ARIA 1.3, which is unreleased and not supported yet.

aria-describedby

The aria-describedby attribute is used to link longer information text to an element.

This description does not replace an aria-label or aria-labelledby. A description can be used with or without an aria label and will always be announced after the label or text content was.

To make sure the screen reader does not repeat the content of the description right after it was read from the button, you should hide the description itself from the accessibility tree with aria-hidden="true".

You can specify multiple descriptions in the aria-describedby attribute by separating them with whitespace, similar to specifying multiple label parts in aria-labelledby.