empty alt may be OK in some situations
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.
Current behaviour:
- Missing alt tags trigger an error unless
IgnoreAltMissingis set - Empty alt tags trigger an error unless
IgnoreAltMissingis 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
IgnoreAltMissingis 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
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.
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
figcaptionand 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.
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.