The Rules of ARIA Use in HTML

Back to Overview
00:00 --> 00:24
with these ARIA things. There are a couple of rules of how to use ARIA in HTML and I tried to, like, hit them all during what we talked about, but they are actually in this really nice document called Using ARIA that Steve Faulkner and others are working on.

00:24 --> 00:30
And it's a really nice summary of what you should and shouldn't do with ARIA when you're using it in HTML.

00:31 --> 00:33
And so let's go to the first rule of ARIA.

00:34 --> 00:40
If you can use a native HTML element or attribute with the same semantics and behavior you require,

00:41 --> 00:49
already built in, instead of repurposing an element and adding ARIA role, state or property to make it accessible, then do so.

00:49 --> 00:56
So, if you need a button, don't use a div with a role button, just use the button element.

00:56 --> 00:58
That's basically what this says.

00:59 --> 01:07
Make sure that whenever there is something in HTML that meets your use case, that you use that.

01:09 --> 01:15
Second rule of ARIA is do not change native semantics unless you really, really have to.

01:15 --> 01:20
and I would add, and you know what you're doing because this can go wrong really quickly.

01:21 --> 01:27
So here's a bad example. It's an H2 roll button detailed information.

01:28 --> 01:35
Now I've talked about, so the use case would be the programmer wants a heading and when you click

01:35 --> 01:45
the heading, it expands and collapse some detailed information. And the thing is twofold. So first,

01:45 --> 01:51
just putting roll button on the h2 does not make the h2 interactive it just gets announced

01:51 --> 01:57
differently to screen readers but actually tabbing to the h2 or doing anything with that

01:57 --> 02:04
that doesn't work because it's not defined it's just a different role and the other thing is that

02:04 --> 02:13
this h2 now ceases to be a heading level two though roles are only like replacing you can't

02:13 --> 02:20
add them to each other. That would be neat, but that's not how they work. So if you put H2RollButton,

02:21 --> 02:28
this heading is not a heading anymore. It's now a button only. So if you're using heading

02:28 --> 02:35
navigation, for example, you would skip right over it. And even in this case, if you use tab

02:35 --> 02:42
navigation and want to activate it, it won't work because you can't actually move your focus.

02:42 --> 02:50
on the button. A much better way is to just use the H2 as you did before and then use the button

02:50 --> 03:00
element inside it and boom your expand collapse is more accessible. It's really simple and so you

03:00 --> 03:06
should always you know always thinking about like oh can I do this through nesting or can I do that

03:06 --> 03:36
in a better way. A third rule of ARIA use is all interactive ARIA controls must be usable with the keyboard. So we just talked about that like this pseudo button was not a keyboard usable. And if you use a roll button, then you need to make sure that the button can receive focus and that a user must be able to activate it both with the enter or return key.

03:36 --> 03:44
or with the space key, because that's how a user assumes that those buttons will work.

03:44 --> 03:50
And that's super important also for the different like widget roles and other things.

03:50 --> 03:57
There is, we see that in a couple, I will point you at the documentation for that.

03:58 --> 04:02
Basically, all these like more complicated user interface components,

04:02 --> 04:08
they have their own requirements on how they must be used with the keyboard.

04:09 --> 04:14
Because basically you're making a promise with the role on how this would work.

04:14 --> 04:23
And if you don't keep that promise, then it will be much, much harder for a user to interact with the widget.

04:26 --> 04:32
Fourth rule of ARIA, do not use role presentation or ARIA hidden true on a focusable element.

04:32 --> 04:37
And as I said, role none is the same as role presentation.

04:39 --> 04:45
When you use either of those, it might result that users are focusing on nothing.

04:46 --> 04:50
So basically you tap to a button and has a role presentation on it.

04:51 --> 04:55
It will just read the text inside of the button like it would be a text field.

04:55 --> 05:00
But there's no announcement that it is a button because you removed the role.

05:01 --> 05:04
That happens when you use rolePresentation or roleNone.

05:04 --> 05:13
If you use aria-hidden true, that hides the element completely from the accessibility tree.

05:14 --> 05:20
So in that case, you could tap to it, but there will be just no announcement.

05:21 --> 05:23
It will be just silence.

05:24 --> 05:26
And obviously, that's not a good interaction.

05:27 --> 05:30
So this is not allowed. Don't do it.

05:30 --> 05:39
And this, by the way, also applies to stuff that is inside of elements that have those, that have aria-hidden set, for example.

05:40 --> 05:43
So I do have examples.

05:43 --> 05:49
So if I have an aria-hidden true and a button inside of that, then that button is also hidden.

05:50 --> 05:59
And you can tap to it or you can move to it using the screen reader and you would have no announcement at all.

05:59 --> 06:24
And the final rule, rule number five, is all interactive elements must have an accessible name. We talked about accessible names and yeah, that's just the rule. Don't do, yeah, use accessible names. Make sure that they have them.