Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does CSS opacity affect accessibility?

After browsing a number of Google and other SO articles, I've decided to ask my question plainly in hopes of a simple, direct answer.

To add one further step to the discussion on Does opacity:0 have exactly the same effect as visibility:hidden: I understand that display:none and visibility:hidden hide elements from screenreaders and the like, but what about opacity:0?

The table in one of the answers to the linked question notes that opacity participates in taborder, so does that necessarily mean it will be mapped to the accessibility API?

Setting a giant negative text-indent is typically offered as an alternative to display: none and visibility: hidden for dropdown menus, but I'd like to fade my menus in and out without JavaScript, while making sure I don't hide them from screen readers.

like image 878
Greg Perham Avatar asked Jan 29 '12 21:01

Greg Perham


People also ask

What is the use of CSS opacity?

Definition and Usage The opacity-level describes the transparency-level, where 1 is not transparent at all, 0.5 is 50% see-through, and 0 is completely transparent. Note: When using the opacity property to add transparency to the background of an element, all of its child elements become transparent as well.

Do screen readers read opacity 0?

Accessibility Implications For opacity: 0An element is hidden with opacity: 0 will still be accessible to screen readers, and focusable with the keyboard.

Does opacity 0 hide from screen readers?

If you need to hide the opacity 0 content from screen readers you need to use aria-hidden="true" on the container element. display: none/visibility hidden will hide your content from screen readers.

Does visibility hidden affect accessibility?

The main reason the visibility: hidden rule isn't just about visual visibility is because it affects the elements visibility to assistive technology as well. When we apply visibility: hidden to an element, it also removes it from the accessibility tree, which makes it invisible to technologies like screen readers.


2 Answers

While this is an older question, it was one of the first that surfaced in a Google search, so I wanted to chime in.

As of April 2017, the ChromeVox screen reader does not read content that is set to opacity 0.

Specifically, ChromeVox won't read text that has been visually hidden with opacity set to zero, unless the element is labeled by visually available text.

For example:

<!-- will not be read -->
<a href="#!" style="opacity: 0;">not read</a>

<!-- WILL be read -->
<a href="#!" style="opacity: 0.001;">is read</a>

<!-- span text will not be read -->
<a href="#!">
  Read More
  <span style="opacity: 0;">
    this will not be read
  </span>
</a>

<!-- 
  button text will not be read, 
  but aria-labelledby text will be read on button focus 
-->
<span id="test">button label</span>
<button type="button" aria-labelledby="test" style="opacity: 0;">
  This text will not be read
</button>
like image 126
scottohara Avatar answered Oct 05 '22 23:10

scottohara


opacity: 0; won't hide content from screen readers, though it'll hide content from sighted users and partially sighted users.
It's like displaying a white text on a white background (or transparent, you get the idea).
It'll be mapped to the accessibility API, you should still see the pointer changing above links, edit: you can still select text /edit, and somebody should test to see if, when tabulating links and form elements, the default dotted outline will display as usual or will be transparent. Edit: the latter, just tested with Firebug on this page.

like image 33
FelipeAls Avatar answered Oct 05 '22 22:10

FelipeAls