Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

alt text generated from filename can be harmful for screen reader users #30096

ckundo opened this issue Aug 6, 2017 · 9 comments


Copy link

ckundo commented Aug 6, 2017

馃憢 Hi Rails friends! Here's something that's been on my mind, hopefully helpful for improving Rails accessibility support:

Autogenerated alt text based on filename creates na茂ve descriptions that can do more harm than good. The content generated by automatically adding alt text can lead to a 300% increase in reading content, creating fatigue for screen reader users. If the content is not useful, this is a waste.

Autogenerated alt text also creates false negatives for linting tools that look for images that need descriptions.

If I'm adding a logo to a header in a document, I may use the image_tag helper.

<%= image_tag "logo.png" %>

That renders:

<img src="/images/logo.png" alt="Logo" />

The alt text "Logo" will be announced to screen reader users (blind, low vision, and sometime dyslexic folk). "Logo" is not a useful description and adds unnecessary content.

This whitepaper on alt text by TPG suggests that filenames as alt text are often useless.

The results clearly indicate that the amount of content conveyed to the screen reader user is increased by around 300% (comparing the length of the texts from the Fangs output) when no alt text is provided. How much of this is useful? From reading or listening to the output it is clear that the file names do not provide any clue to what is contained within the images

Expected behavior


In the logo.png example, the alt text should read the company name. There might be heuristics to automate that, but even in this simple case it's likely easier and more robust to rely on the author.

It is common practice on the web to have the main site logo also link to the site home page. Because this is fairly standard practice, providing alternative text for the image, such as your company name (alt="Acme Company), will usually suffice. Identifying the logo as actually being a logo (alt="Acme Company Logo") is not typically necessary. The content and function is not "logo".

image_tag ideally would not add automatically generated alt text. The behavior for screen reader users would not change much, since most screen reader tech falls back on filename with no alt text is present anyways. It may cause automated testing an linters to fail since no alt attribute is added. These failures would arguably be correct.

Next best solution would be an application level configuration options to set filename autogeneration.

config.action_view.alt_text_default = :filename

System configuration

Rails version:
Rails 5.1.3

Ruby version:
ruby 2.4.1

Copy link

Completely agree with this proposal. Working on various client sites and sifting through their image libraries, I find more often than not, that their file names are merely just the default naming strings from their phones or digital cameras.

Copy link

mgifford commented Aug 7, 2017

This is what I proposed for Drupal

Ultimately you could create a means to programmatically determine if a string looks like a filename (no spaces, a period followed by 2-4 letters) and use that associated with some common blacklist words (image, alt, alt text, photo). Not that you couldn't use a filename or blacklisted word, but you couldn't just use them.

Anyways, hope this gathers some support.

Copy link

Thanks for proposing this! I鈥檓 in favor of dropping the filename fallback altogether.

[M]ost screen reader tech falls back on filename with no alt text is present anyways鈥

The cited whitepaper confirms that JAWS, the most popular screen reader for Windows, does this.

Copy link

georgeclaghorn commented Aug 7, 2017

Actually, after thinking about it more, I don鈥檛 quite understand how removing the filename fallback would help.

The whitepaper you cited says that the 300% increase in readable content comes from not populating alt attributes 鈥 rather than populating alt attributes according to a heuristic 鈥 and Rails鈥檚 heuristic is at least a reasonable guess at an image description. That means removing the filename fallback wouldn鈥檛 meaningfully reduce the amount of readable content on any given page. It also wouldn鈥檛 make readable content more informative or useful.

To fix the problem you鈥檙e pointing out, Rails would need to somehow enforce that alt attributes are populated with meaningful descriptions, no? That doesn鈥檛 seem reasonable.

Copy link

mgifford commented Aug 7, 2017

Assistive Tech often tries to do hacky things like use the file name in the hopes that it might give the blind user more context. In generally falling back to the filename is a bad idea though. JAWS is a very configurable program and it is very likely that a user could enable or disable this.

Here's the reference to the ATAG 2.0 reference:

Drupal 8 is requiring alt text by default:

This is a different program/community. Still, worth while reaching out to what we've done in the past for guidance.

Copy link

Thanks for the clarification. I鈥檓 in favor of removing the fallback in Rails and leaving it up to the screen reader. 馃槃

Copy link
Contributor Author

ckundo commented Aug 7, 2017

Thanks for the responses so far! Really appreciate this is getting discussion.

@georgeclaghorn I have some thoughts!

The whitepaper you cited says that the 300% increase in readable content comes from not populating alt attributes

I revisited the whitepaper too, I see now I didn't understand the 300% increase measurement at first glance. My first impression was that they were using empty strings as the values for the alt attributes, that removes the nodes from the accessibility tree altogether and would make the content much shorted. Admittedly I'm a little confused by that now! (paging @stevefaulkner)

Generally though, I can say from observation and experience that filename based generated alt text is unreliable at best, and at worst and can distracting and fatiguing for people using screen readers. I can work on getting some empirical research, but I think anecdotally it stands to reason that teams are not naming images with alt text as a core motive.

To fix the problem you鈥檙e pointing out, Rails would need to somehow enforce that alt attributes are populated with meaningful descriptions, no? That doesn鈥檛 seem reasonable

This is at the core of the concern. I don't think it's Rails's job to enforce alt text at all. It'd be better to do nothing and let linters or other tooling to pick up the missing alt text.

That's all to say that filename alt text generation obscures the nuances of image description that really should be up to the author to decide. I 鉂わ笍 convention over configuration, but in this case file name based text is not a sane default and might create a false sense of completeness.

To the point of "completeness", this also has bearing on standards and accessibility guidelines (and laws). I don't believe that the feature was built to "check the box" for WCAG 2.0 and Section 508 requirements, but it has the side effect of doing so in a half-baked way, and so makes it harder to identify failures to apply alt text thoughtfully. That's what I had in mind when I brought up automated testing and linting.

That's where I'm at right now. George, does that address your concerns? Do we think there are more ways we bring this closer to a solution?

Copy link
Contributor Author

ckundo commented Aug 7, 2017

@georgeclaghorn I can put together a PR for this if it's something you're willing to review!

Copy link

@ckundo please

ckundo added a commit to ckundo/rails that referenced this issue Aug 17, 2017
- Auto-generating content from the filename of an image is not suitable
  alternative text; alt text that isn't fully considered can be
  distracting and fatiguing for screen readers users (blind, low vision,
  dyslexic people).
- Setting a filename fallback short circuits screen reader default
  behavior and configuration for blank descriptions.
- Setting poor defaults also creates false negatives for accessibility
  linting and testing software, that makes it harder to improve
  application accessibility.


- After this change, if authors leave images without alt text, screen
  readers will fallback to default behavior for missing alt text.
- Also with this change, Automated linting and testing tools will
  correctly generate warnings.

[Fixes rails#30096]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

5 participants