Let's say you have a picture element similar to this:
<picture class='my-image'>
<source media="(min-width: 1024px)" srcset="large.jpg">
<source media="(min-width: 768px)" srcset="med.jpg">
<source srcset="small.jpg">
<img src="small.jpg" alt="">
<p>Accessible text</p>
</picture>
But let's say that the context of the image is different for each breakpoint. Perhaps at large size, the picture is of a man standing in front of a tree. But at mobile size, it's just a picture of a tree.
Sometimes, certain pictures work well at mobile sizes and other pictures don't depending on page layouts, etc.
Anyways, with the picture element you can only specify the alt=
attribute in a single place for the entire picture element. But if the image context changes between each breakpoint, is it possible somehow to specify different alt=
attributes? Do you have to use JavaScript for this (which may or may not be screen reader friendly)?
It looks to me that this kind of situation appears only when using a strictly "decorative image".
If those images are stictly decorative and you can't put them for certain reasons in CSS, then the alternative text has to be empty.
If they are not decorative images, then the easiest solution is to use two different
picture
tags which does not require any Javascript.