Background image is a CSS style and CSS has no alt
attribute — that belongs to the HTML.
If you’re getting a warning about a missing alt
attribute, that must be somewhere else on the page — not the code you’re showing here.
Can you explain why the div has this attribute?
So the image can go in the background, and text, another image or something else can be placed on top of it. That’s why it’s called “Cover” block.
Does this make screen readers treat it as an , and so expect some alt-text?
As I mentioned earlier, this is a CSS style and screenreaders will simply ignore it as if it doesn’t exist… just as they ignore colors and whatnot.
Here’s what the Mozilla Developer Docs says about the background-image property and accessibility:
Accessibility concerns
Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page’s overall purpose, it is better to describe it semantically in the document.
In short only use background images, whether for the cover block or something else, for decorative purposes.
Yes, I know that about the accessibility of background images. And yes, it is definitely the background image div that is getting highlighted in the accessibility audit.
Your explanation as to why the div has the “role=’img'” attribute does not make any sense to me. Clearly, the div could contain a background image without the “role” attribute.
As MDN docs state, the “img” role attribute is generally used for an element containing multiple images, and there should also be an “aria-label” attribute.
Your explanation as to why the div has the “role=’img’” attribute does not make any sense to me.
It doesn’t make any sense to me either 🙂
My bad: I read your post completely (at least I believe I did!), but I never saw the part about the ARIA role at all. So I answered the question of why a background image is used… not why there’s the role="img"
in the div.
Very sorry about that!