Currently on our website, there is a component that utilizes an <a>
tag with a background image set by the following CSS:
a.class-name::after {
content: url('image.png');
}
The anchor tag itself has no visible content (appears as
<a class="class-name" other-attrs></a>
). The issue at hand is the need to include alt-text for accessibility. As anchor tags do not support the alt
attribute, I am considering two solutions:
- Injecting alt-text within the tag and then styling it to be invisible. There is concern whether this approach will be captured by screen readers, as they may detect hidden text.
- Including the alt-text in the
title
attribute of the tag. Although typically disregarded by screen readers, it has been noted that "the only very tiny exception a title attribute will be read is if there’s absolutely no link anchor text, and that’s rare". In our case, this scenario fits perfectly, but further verification from experts is warranted.
Is there a potentially superior third alternative? Regardless, any guidance on this matter would be greatly valued!