Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding aria-hidden true for all images

Is it true that if I add aria-hidden="true" for all the images on my website, I wouldn't have to add an alt text to those images because it would basically not be displayed for screen readers or how would validates handle this scenario? Is it recommended to do?

like image 247
user2945872 Avatar asked Feb 17 '17 08:02

user2945872


People also ask

What does aria hidden true mean?

Adding aria-hidden="true" to an element removes that element and all of its children from the accessibility tree. This can improve the experience for assistive technology users by hiding: Purely decorative content, such as icons or images. Duplicated content, such as repeated text.

Should images have aria-label?

The aria-label attribute should only be used to provide a text alternative in the special case when an element has a role="img" attribute. Use the alt attribute for img and area elements.

Do you need aria hidden with display none?

Hiding content from all users If you want to hide content from all users, use the HTML5 hidden attribute (along with CSS display:none for browsers that do not yet support hidden) There is no need to use aria-hidden.

How do I add a hidden user to my aria?

To hide an element to screen readers (and child elements), simply add the aria-hidden="true" attribute. Content can still be made accessible to ATs via aria-describedby or aria-labelledby .


2 Answers

If you're using a CMS and the image is decorative you need to be able to output a blank alt attribute, e.g., <img src="<imagesource>" alt="" />.

If you're hand coding the page and can add the decorative images in through CSS that's another approach.

WCAG 1.1.1 says that non-text content must have a text alternative. That text alternative must have the equivalent purpose. One of the exceptions is for decorative images, images used for formatting, or that would be invisible to everyone (e.g., tracking gifs). These must be "implemented in a way that can be ignored by assistive technology". The accepted method is to have a nullalt attribute, as a missing alt attribute would be read out.

In theory aria-hidden=true would work, but that requires the technology to understand aria. Null (blank) alt attributes have been established a lot longer and will be accepted by more assistive technologies so it's the appropriate way of having an img element on the page that's not read out by screenreaders.

like image 80
Karl Brown Avatar answered Sep 29 '22 11:09

Karl Brown


If you don't want to add an alternative text to images (because they are purely decorative and the content could be understood without them), you can leave the alt parameter empty.

There's no need to add aria-hidden attribute.

The best thing to do is to use CSS for decorative images.

like image 38
Adam Avatar answered Sep 29 '22 13:09

Adam