If I am using a background image in an anchor tag as a menu, what is the best way to provide a text label equivalent for screen readers and SEO?
Assume the HTML is like this:
<h2><a class='menuItem1'></a></h2>
And the CSS is like this
.menuItem1 {
display:block;
width:100px;
height:25px;
background-image:url(../Images.menuitem1.png);
}
Should I use title="..." as well at alt="..." on the A tag? My test using the Lynx browser seems to only show a label if there is text in the A tag as well.
altonly exists on the<img>tag. If your image is actually a meaningful part of the web page, and not just stylistic, then you can just use an actual<img>tag with analtattribute.Alternatively, you could put the actual text inside the
<a>tag, and hide it using CSS. Sincedisplay: nonewill also hide it from screen readers, you would need to instead hide it with something liketext-indent:-9999px;