One challenge I am facing is that my website displays images as background images using background-size: cover
to fill the element completely and crop out any excess parts of the image. However, these images are not just decorative; they are essential for conveying information on the page. To make them accessible to screen readers and assistive technologies, they need alt
text descriptions.
I'm wondering what the best approach is to add alt
descriptions to background images in a semantic way.
article {
position: relative;
width: 320px;
margin: 5rem auto;
}
figure {
width: 100%;
height: 180px;
/* not accessible */
background-image: url('http://www.fillmurray.com/300/300');
background-size: cover;
background-position: center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<article class="panel panel-default">
<header class="panel-heading">
<h4 class="panel-title">Title of Article</h4>
</header>
<div class="panel-body">
<figure class="article-image"></figure>
</div>
<footer class="panel-footer">
<a class="btn btn-default" href="#">Read</a>
</footer>
</article>