While digging into this accessibility journey, you might have heard me say a couple of times that semantics always win. However, this wasn't always the case.
Before HTML5, we didn't have all the fancy semantic elements like
main. These kinds of elements were always described as plain divs with some markup.
That made it nearly impossible to define these elements as assertive technologies.
Hence WAI-ARIA comes to life.
What is WAI-ARIA
You might be wondering what it even is, and it stands for
Web Accessibility Initiative - Accessible Rich Internet Applications. It's a specification written by W3C defining a set of attributes you can use to provide additional semantics.
They are divided into multiple sections:
- Roles: Can be defined by using
- Properties: Give extra meaning to an element for example:
- States: Describe the current condition of an element for example:
All these WAI-ARIA only helps assertive technology to understand your webpage better. They do not physically have any other impact on how your website behaves.
When to use WAI-ARIA
You might have seen a couple of examples in this A11Y series where we used some of the WAI-ARIA's, and a general rule of thumb is:
"Only use them when you have no other native method".
They should be a last resort in making things accessible when native elements aren't sufficient.
Is a valid example, but we should opt for the semantic alternative:
You might be wondering, ok, which roles can I use then, and what are the alternatives?
And that would be a bit too much to explain in this article. So more on that in the next one as we deep dive into all the roles.
Another part where the WAI-ARIA's come to live is providing dynamic content updates for screen readers.
For example, there is the aria-live, which can be used to notify screen readers when content updates. Think about notifications on the screen or new content that gets refreshed.
A great example of an element heavily relying on WAI-ARIA's is the tab element we recently built.
Look at that article and see if WAI-ARIA makes more sense now.
WAI-ARIA's can enhance semantics and accessibility but should only be used as a last resort.
There is an impressively long list of elements, for which I'll write singular articles to go more in-depth.