htmltest icon indicating copy to clipboard operation
htmltest copied to clipboard

empty alt may be OK in some situations

Open tcurdt opened this issue 5 years ago • 4 comments

It seems in a situations where there is a related/sibling figcaption the alt attribute may be OK to be left empty for img tags.

https://stackoverflow.com/questions/58447538/accessibility-difference-between-img-alt-and-figcaption

It probably should be configurable whether that situation is considered an error or not.

tcurdt avatar Nov 10 '20 15:11 tcurdt

Current behaviour:

  • Missing alt tags trigger an error unless IgnoreAltMissing is set
  • Empty alt tags trigger an error unless IgnoreAltMissing is set

Wasn't quite sure of the best solution for this but after a bit of reading I've come to this conclusion:

  • Empty alt tags may trigger an error depending on new config IgnoreAltEmpty
  • Missing alt tags will continue to trigger an error unless IgnoreAltMissing is set

I'm undecided on whether IgnoreAltEmpty should be enabled by default. I'm leaning towards no. This both preserves existing behaviour and makes user think about what they're doing.


Some articles for future reference:

  • https://thoughtbot.com/blog/alt-vs-figcaption
  • https://davidwalsh.name/accessibility-tip-empty-alt-attributes

wjdp avatar Jan 14 '21 22:01 wjdp

I'm undecided on whether IgnoreAltEmpty should be enabled by default. I'm leaning towards no. This both preserves existing behaviour and makes user think about what they're doing.

I agree with that - but IMO also the context matters. IIUC these are very general options while the figcaption seems to be a very specific situation. But I would only want to allow empty/missing alt attributes in this very case.

tcurdt avatar Jan 14 '21 22:01 tcurdt

Context does matter and this extends beyond the usage of figcaption. An intentional empty alt tag can be valid in a few contexts. The two I know of:

  • When using figcaption and the alt text would be the same as the caption.
  • For decorative elements where the image adds no information to the page (see https://www.w3.org/WAI/tutorials/images/decorative/)

Both require a conscious decision to omit the alt text. I had two options in mind. Am a little undecided.

Attribute

Look for a data-htmltest-allow-missing-alt (or similar name) attribute which would disable the check, would look like:

<img src="..." alt="" data-htmltest-allow-empty-alt />
<img src="..." data-htmltest-allow-missing-alt />

This is very similar to the data-proofer-ignore attribute we already have that just disables every check on a tag.

Use alt="" as the indicator combined with IgnoreAltEmpty

My initial thought. An empty alt attribute can be a marker of intent. If you intentionally produced <img src="..." alt="" /> then we can allow it.

Thinking about this now you could very easily produce that tag from a faulty templating system which is what this tool is used to catch! I'm now less fond of this idea.

wjdp avatar Jan 15 '21 00:01 wjdp

In my case the img is being generated by a markup conversion. So the data-htmltest-allow-missing-alt wouldn't really work for me. But on the other hand I wouldn't want to allow empty alt attributes everywhere.

tcurdt avatar Jan 15 '21 09:01 tcurdt