Giter Site home page Giter Site logo

Comments (6)

fvsch avatar fvsch commented on July 19, 2024 1

I wrote a test, and ran it with VoiceOver on Yosemite, using default settings.
Test page: https://dl.dropboxusercontent.com/u/145744/accessible-svg-icon/test.html

I tested two situations, since they seem to differ quite a bit: when the SVG is in a button or link (results were similar in VoiceOver), and when it's in regular text flow.

Without a button or link, the SVG icon is generally not read. (Not read at all in Safari, read as "Image" but no alt text in Firefox.) The only way to get alternative text I found was with a visually hidden element (that must not be 0 by 0 pixels, or it won’t be read).

Inside a button or link, VoiceOver will do its best to read alt text. It will read:

  • Neighboring text, including a visually hiddden <span>
  • The aria-label if there is one
  • The <title> element from the <symbol>

It will NOT read:

  • The title attribute (at least not with default settings)
  • The symbol’s <title> if we used aria-hidden="true" on the SVG icon

Finally, if we use both a <title> (with no aria-hidden="true") and an aria-label, the aria-label will take priority.

So my final recommendation would be:

Button with a single icon:
<button aria-label="Button label">
  <svg aria-hidden="true"><use xlink:href="..."></use></svg>
</button>

Button with an icon and visible label:
<button>
  <svg aria-hidden="true"><use xlink:href="..."></use></svg>
  Button label
</button>

from svg4everybody.

larsenwork avatar larsenwork commented on July 19, 2024

@fvsch any reason not to use role="img" instead of aria-hidden="true" ?

from svg4everybody.

fvsch avatar fvsch commented on July 19, 2024

@larsenwork With role="img" screen readers might try to read the SVG image (especially if it happens to have a <text> element), and we’re already providing the relevant text either in context or as an aria-label on the parent. So I’m trying to avoid readings like "Button the actual label Image".

Of course if for whatever reason you’re trying to get screen readers to read the icon itself, you don’t want to use aria-hidden="true". In my latest tests, adding role="img" had no effect and I think it might be redundant with the <svg> element anyway. The one technique that had good results was using a title element:

<svg>
  <title>Alt text</title>
  <use xlink:href=""></use>
</svg>

But I’ve seen contradictory results elsewhere, so I need to check my tests.

from svg4everybody.

jonathantneal avatar jonathantneal commented on July 19, 2024

I was testing this today and I needed aria-label for consistent results with role="img", so I will be updating the recommendation.

from svg4everybody.

sathomas avatar sathomas commented on July 19, 2024

@jonathantneal In a similar manner to pull request #108, you might want to maintain the aria-labelledby attribute for <use> elements. That would provide better support for code such as the following:

<symbol id="icon" aria-labelledby="icon-title" viewBox="0 0 65 65">
    <title id="icon-title" lang="en">icon</title>
    <path d="..."/>
</symbol>

(I had thought about including that in the PR, but decided to start more modestly.)

from svg4everybody.

fvsch avatar fvsch commented on July 19, 2024

@sathomas Is that supported in other screen readers beyond VoiceOver?

In my tests:

  • VoiceOver read the <title> element from a used <symbol>, and didn’t the aria-labelledby attribute for that.
  • JAWS and NVDA didn’t support it at all in used <symbol> elements, with or without aria-labelledby.

So aria-labelledby seems redundant and useless here.
Similarly for <title> as child of the <svg> element which is being read (rather than a separate <symbol>): supported in all 3 screen readers without aria-labelledby.

from svg4everybody.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.