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?
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.
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.
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With