On my web page I have an anchor (code below), which I visually display as an image (logotype) completely hiding the text. I'd like the anchor to be:
- accessible - read properly by screen readers,
- display a tooltip when hovered by mouse (the tooltip explains the image logotype, which may not be understood by everyone).
I use the following method:
HTML
<a href="http://some-institution.com"
title="Some Institution"
class="replace-text-with-image">Some Institution</a>
CSS
.replace-text-with-image {
/* Hide the text. */
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
/* Display the image. */
width: <image-width>;
height: <image-height>;
background-image: url(<url-to-image>);
background-size: <image-width> <image-height>;
background-repeat: none;
}
The problems with the method above:
- A guy reported to me that on encountering the link his screen reader reads both the link's contents ("Some Institution") and then the link's
title
("Some Institution" again), resulting in a "stutter". - I read (in this article) that using
title
for accessibility is wrong andaria-label
should be used instead.
So I tried re-factoring to use both aria-label
and title
:
<a href="http://some-institution.com"
title="Some Institution"
aria-label="Some Institution"
class="replace-text-with-image">Some Institution</a>
Now NVDA (the screen reader I'm testing on) reads both title
and aria-label
attributes resulting in a stutter again.
Other possible solutions which won't work:
- When I remove the
title
attribute and leave onlyaria-label
it's read fine, but I can't removetitle
attribute, as that's an explanation for the visual users that I want to have. - I could also stay with just
title
attribute completely removing anchor's contents, but I feel having an empty anchor is not a particularly good practice, isn't it?
What's a solution for that problem?