ARIA in CSS

Sara tweeted something recently that resonated with me:

Also, Pro Tip: Using ARIA attributes as CSS hooks ensures your component will only look (and/or function) properly if said attributes are used in the HTML, which, in turn, ensures that they will always be added (otherwise, the component will obv. be broken)

Yes! I didn’t mention it when I wrote about accessible interactions but this is my preferred way of hooking up CSS and JavaScript interactions. Here’s old Codepen where you can see it in action:

[aria-hidden='true'] {
  display: none;
}

In order for the functionality to work for everyone—screen reader users or not—I have to make sure that I’m toggling the value of aria-hidden in my JavaScript.

There’s another advantage to this technique. Generally, ARIA attributes—like aria-hidden—are added by JavaScript at runtime (rather than being hard-coded in the HTML). If something goes wrong with the JavaScript, the aria-hidden value isn’t set to “true”, which means that the CSS never kicks in. So the default state is for content to be displayed. There’s no assumption that the JavaScript has to work in order for the CSS to make sense.

It’s almost as though accessibility and progressive enhancement are connected somehow…

Have you published a response to this? :

Responses

Sara Soueidan

“ARIA in CSS” adactio.com/journal/17566 in which @adactio elaborates on my previous tweet on using ARIA attributes as style hooks in #CSS — “the default state is for content to be displayed. There’s no assumption that the JavaScript has to work in order for the CSS to make sense”

6 Likes

# Liked by Chris Taylor on Tuesday, October 27th, 2020 at 6:31pm

# Liked by Aleksi Peebles on Tuesday, October 27th, 2020 at 6:46pm

# Liked by Marty McGuire on Tuesday, October 27th, 2020 at 7:08pm

# Liked by Lucid00 on Tuesday, October 27th, 2020 at 8:00pm

# Liked by George Salib® on Tuesday, October 27th, 2020 at 9:42pm

# Liked by Zachary Dunn on Wednesday, October 28th, 2020 at 1:01pm

Related posts

Performative performance

When it comes to sustainable web design, the hard work is invisible.

The intersectionality of web performance

Business, sustainability, and inclusivity.

Alt writing

Aiming for originality and creativity in alt text.

Image previews with the FileReader API

Adding `alt` text to uploaded images.

Even more writing on web.dev

Five more articles on modern responsive design to close out the course.

Related links

80 / 20 accessibility · marcus.io

So my observation is that 80% of the subject of accessibility consists of fairly simple basics that can probably be learnt in 20% of the time available. The remaining 20% are the difficult situations, edge cases, assistive technology support gaps and corners of specialised knowledge, but these are extrapolated to 100% of the subject, giving it a bad, anxiety-inducing and difficult reputation overall.

Tagged with

The Web Accessibility Cookbook

Manu’s book is available to pre-order now. I’ve had a sneak peek and I highly recommend it!

You’ll learn how to build common patterns written accessibly in HTML, CSS, and JavaScript. You’ll also start to understand how good and bad practices affect people, especially those with disabilities.

Tagged with

Home - Sa11y

Another handy accessibility testing tool that can be used as a bookmarklet.

Tagged with

Write Alt Text Like You’re Talking To A Friend – Cloud Four

This is good advice:

Write alternative text as if you’re describing the image to a friend.

Tagged with

I worry our Copilot is leaving some passengers behind - Josh Collinsworth blog

Products of all kinds are required to ensure misuse is discouraged, at a minimum, if not difficult or impossible. I don’t see why LLMs should be any different.

Tagged with

Previously on this day

13 years ago I wrote Stallmania

Surprise parrot.

18 years ago I wrote Comments on comments

Examining the results of the comment experiment.

21 years ago I wrote Banksy in Brighton

It looks like graffiti artist Banksy was in Brighton recently. I spotted some of his work near the North Laine.

23 years ago I wrote A brush with fame

Chris (my upstairs neighbour and bandmate) had an interesting encounter this morning.