I wrote a little something recently about using ARIA attributes as selectors in CSS. For me, one of the advantages is that because ARIA attributes are generally added via JavaScript, the corresponding CSS rules won’t kick in if something goes wrong with the JavaScript:

Generally, ARIA attributes—like aria-hidden—are added by JavaScript at runtime (rather than being hard-coded in the HTML).

But there’s one instance where I actually put the ARIA attribute directly in the HTML that gets sent from the server: aria-live.

If you’re not familiar with it, aria-live is extremely useful if you’ve got any dynamic updates on your page—via Ajax, for example. Let’s say you’ve got a bit of your site where filtered results will show up. Slap an aria-live attribute on there with a value of “polite”:

<div aria-live="polite">
...dynamic content gets inserted here

You could instead provide a value of “assertive”, but you almost certainly don’t want to do that—it can be quite rude.

Anyway, on the face it, this looks like exactly the kind of ARIA attribute that should be added with JavaScript. After all, if there’s no JavaScript, there’ll be no dynamic updates.

But I picked up a handy lesson from Ire’s excellent post on using aria-live:

Assistive technology will initially scan the document for instances of the aria-live attribute and keep track of elements that include it. This means that, if we want to notify users of a change within an element, we need to include the attribute in the original markup.

Good to know!

Have you published a response to this? :


1 Like

# Liked by Zachary Dunn on Tuesday, November 10th, 2020 at 6:57pm

Previously on this day

2 years ago I wrote Webmentions at Indie Web Camp Berlin

Technical and ethical questions.

4 years ago I wrote We must love one another or die

We must love one another and die

17 years ago I wrote Revolutions Reviewed

I went to see The Matrix Revolutions over the weekend. I enjoyed it. Then again, I enjoyed The Matrix Reloaded so what do I know?

17 years ago I wrote Brave Old World

I find it strange to read an article that I completely and utterly disagree with. It’s like being afforded a glimpse into an alien mind.