Is it accessible to hide image links using tabindex="-1" aria-hidden="true" on the anchor tag if the image as alt="", provides no real content value, and is purely decorative?
My example below is of a "product listing" style of content. This is really a follow-up question to What is best practice (and legal) for product listing image alt text for accessibility? regarding best practices for product listings, but could be relevant in other scenarios. While ideally you may just have one anchor tag wrapping both the image and product name elements, this might not be possible based on other content within the list block or if you don't have enough control of the actual markup to move this around depending on the project you are working on.
In these cases, I still need the image clickable for users, but don't want to force screen reader users to have to tab through redundant links and listen to duplicate/unnecessary content. I've tested this on VoiceOver and NVDA and it appears to work well.
Is this a valid method or are there drawbacks that would cause issues for some users?
.product-list {
list-style-type: none;
margin: 1rem 0;
padding: 0;
}
.product-list li {
display: inline-block;
margin: 0;
padding: 0;
text-align: center;
vertical-align: top;
}
.label, .name {
display: block;
}
.sr-only:not(:focus):not(:active) {
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
<h1>Image Anchor Link with Tabindex -1</h1>
<ul class="product-list">
<li>
<a href="/#first-link.html" tabindex="-1" aria-hidden="true">
<img src="https://place-puppy.com/200x200" alt="">
</a>
<span class="label"><span class="sr-only">Label: </span> Featured</span>
<a class="name" href="/#first-link.html">Sparky</a>
</li>
<li>
<a href="/#second-link.html" tabindex="-1" aria-hidden="true">
<img src="https://place-puppy.com/200x200" alt="">
</a>
<span class="label"><span class="sr-only">Label: </span> New</span>
<a class="name" href="/#second-link.html">Fletcher</a>
</li>
<li>
<a href="/#third-link.html" tabindex="-1" aria-hidden="true">
<img src="https://place-puppy.com/200x200" alt="">
</a>
<a class="name" href="/#third-link.html">Tallulah</a>
</li>
</ul>