Accessibility
ARIA
Fills in the accessibility gaps in native HTML by modifying the semantics or context of elements.
5 Rules of Aria
- Always use native HTML elements/attributes over ARIA where possible
- Never change native semantics unless you have no other choice
- All interactive ARIA controls must be usable with a keyboard
- Never use
role="presentation"oraria-hidden="true"on focusable elements - All interactive elements must have an accessible name
The Accessibility Tree
Based on the DOM, but contains only the information used by assistive technologies. ARIA works by modifying the properties of the elements making up this tree. Includes various attributes such as:
- Name
- What assistive technologies announce to the user and use to differentiate between elements of the same type. Can be set natively in HTML, for example by the text contents of an element, its alt text or its label
- Description
- What the element is/does, announced along with the name
ARIA Labels
It’s possible to label an element which can’t usually be labelled using
ARIA, by passing the id of the element to aria-labelled-by or
aria-described-by for example.
aria-described-by-
-
Overrides any native label and replaces the
nameattribute in the accessibility tree. - You pass a string as the value, which becomes the element's accessible name.
-
Cannot be used on
divorspanelements.
-
Overrides any native label and replaces the
aria-labelled-by-
-
Overrides both native labels and the
aria-labelattribute. - Sets the label to a concatenated string of the text contents or alt attributes of the elements whose ids you pass
- Any number of elements can be passed, including the element itself
- Will still be labelled even if the element giving the label is hidden, useful for when you don't want sighted users to see the label
-
Unlike a native
labelelement, does not auto-focus the thing it labels when the 'label' is clicked
-
Overrides both native labels and the
aria-describedby-
Similar to
aria-labelled-by, but for the ARIA description attribute aria-hidden-
Hides elements from the accessibility tree. However be careful as hiding
an element also hides all its children, which can't be overridden bt
setting
aria-hidden=falseon the child elements. Also don't apply it to focusable elements, nothing will be announced when they gain focus.
Useful Links
Chrome extension for accessibility testing.
Firefox Accessibility Inspector
Can scan a page for accessibility issues, and shows the accessibility tree like the DOM.
General performance testing, which also covers accessibility.
A collection of screen reader outputs so you know what you’re making stuff accessible for.