NO BUG: Alt text missing on image block breakpoints

I just did a test because my images didn’t have the alt text showing on the front-end and I found out that if you use the breakpoints for a featured image so you can have a fallback, the alt text does not get displayed on the breakpoint version of the image.

Hey @mrapino,

what do you mean by:

Because if you use breakpoints, you need to create multiple “image” elements anyway. So, I suppose you used “Sources”, right?
In this case, you should see the alt text of the original image, not the one that you defined in “sources”.

Is this the case for you?

Best regards,
Matej

HI Matej,

You misunderstood me. Let me use some visuals.

As you can see, I am using the built-in functionality where you can display {featured_image} for any breakpoint, will the fallback image being the original image of the image block. That is what I meant by “breakpoint”.

I actually discovered that it is worse than just not displaying… I dug a little deeper and it seems that it is displaying the alt text of the fallback image even when the featured image is the image being displayed on the front-end.

Also, it looks like this has been an issue for at least a year so far:

And here is another instance of the same issue:

Hi @mrapino,

in the <picture> element, the alt attribute is specified on the <img> tag, which serves as a fallback for browsers that do not support the <picture> element or when none of the <source> elements match the current conditions/breakpoints.

However, the alt attribute on the <img> tag does not change based on which <source> is being displayed. The alt text remains the same regardless of which image is shown.

If you need different alt text for different images, you would need to use JavaScript, for example, to dynamically change the alt attribute based on some conditions or add multiple Image elements, and show/hide them on different breakpoints.

You can check all <source> attributes here: <source>: The Media or Image Source element - HTML: HyperText Markup Language | MDN, and you will see that alt attribute is not available.

It’s not Bricks limitation, it’s how <picture> element with <source> works. That’s why I will mark this topic as no-bug, and will also update the other two.

Best regards,
Matej

Don’t you think this is a poor application of this functionality? Why would you allow for a different image to be used without pulling its alt text with it? You are stating how it currently works, but it shouldn’t be coded that way. What use is having alt text on an image that is no longer that image?

If you are going to give us the ability to choose a featured image, and have a fallback, the very least you can do it ensure that the correct alt text is used.

This is absolutely a limitation of Bricks.

From an accessibility perspective, Brick is programmed incorrectly, causing a big accessibility issue, as well.

Fixed this myself WITHOUT JAVASCRIPT.

SOLUTION (since none was offered, I will help others with this issue):

@ajercan and @moritzre

You need to use TWO image blocks instead of one.

On the first, choose your fallback image and then use CONDITIONS:

brave_ODKURNlY0h

Then you have a second image block with the dynamic {featured_image} chosen. In conditions you put:

brave_KZD0dXF71w

If you do this, your images will have the CORRECT alt text, and you will also have a more accessible website, since having alt text for a different image than the one shown is absolutely not correct OR accessible.

Hey @mrapino,

thanks for your answers and a possible workaround. Now, since you tagged me in three answers, let me answer you :slight_smile:

No, I think it’s the correct/standard implementation. Like I said earlier, you can check here (<source>: The Media or Image Source element - HTML: HyperText Markup Language | MDN), to see which attributes are available for <sources> element. You will see that different alt attribute is not.

If we call it a limitation, then it’s a limitation of the HTML standard. These guys are defining what sources should support and what not.

Like I said above, the only way for Bricks to provide this, would be to create a custom solution, with JS. Then, you could have a toggle somewhere, if you want this to work so, or not.

Best reagrds,
Matej