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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should an img with no src be mapped to role=img? #439

Open
dd8 opened this issue Oct 7, 2022 · 3 comments
Open

Should an img with no src be mapped to role=img? #439

dd8 opened this issue Oct 7, 2022 · 3 comments

Comments

@dd8
Copy link

dd8 commented Oct 7, 2022

Should the following (non-conforming) img element without src and without alt map to role=img

<img/>

Chrome: nothing rendered on screen, but exposed as role=img
Firefox: nothing rendered on screen, but exposed as role=img
Safari: nothing rendered on screen, not in accessibility tree

The HTML standard and html-aam seem to be at odds here::

  • html-aam maps all img elements without alt to role=img (even if they have no src)
  • the HTML spec says an img with no alt and no src represents nothing (i.e. has no semantics)

The HTML spec says:

If the src attribute is not set and either the alt attribute is set to the empty string or the alt attribute is not set at all
The element represents nothing.

https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element

The HTML spec defines "represents nothing" as meaning the element has no semantics.

This came up in the ACT Rules face-to-face meeting. Usually an img with no accessible name would be a SC 1.1.1 failure, but this looks hard to justify for <img/> since there's no non-text content because there's no src.

Does it make sense to add an element without content, and that's never rendered, to the accessibility tree?

@jnurthen
Copy link
Member

jnurthen commented Oct 7, 2022

personally I agree with the webkit behaviour but until the mappings are fixed it seems reasonable to flag as an error in conformance checkers.
To guide priorities how often does this kind of thing happen in the real world?

@dd8
Copy link
Author

dd8 commented Oct 7, 2022

It's less than 1% of pages for <img> with no src.

The same problem happens (with identical browser/AT results) where src is an empty string:

<img src=''>

This is much more common (around 3-4% of pages) because it's easy to generate from templates like the following:

<img src='{{imgURL}}'> <!-- Handlebars.js / Mustache template -->
<IMG src='{$imgURL}'/> <!-- XSL template -->

@scottaohara
Copy link
Member

After discussion with the wg, seems we should treat this case as an implicit role=none

scottaohara added a commit that referenced this issue Dec 13, 2022
closes #439

This PR provides more detailed conditions for when an `img` element is mapped to the `img` role. 

This was originally brought up to address what should happen when an `img` lacks or has been given an `src` attribute set to the empty string, as HTML defines such instances as "representing nothing".  However, in trying to just add in that condition, it made me realize the mappings were lacking additional nuance to how the element is exposed re: the existence of alternative naming mechanisms besides just `alt`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants