Appropriate way to hide icons from screen readers

允我心安 提交于 2019-12-05 12:01:23
Daniel Imms

You should use the aria-hidden="true" attribute, which says:

Indicates that the element and all of its descendants are not visible or perceivable to any user as implemented by the author.

This means that the element is not supposed to be perceived by any user. So use:

<span class="my-font" aria-hidden="true">c</span>

If the icon is supposed to be a link or is not just for decoration, I suggest you have some text accompanying them so that screen readers knows what it is. You can move the text off screen so that it is only visible to screen readers.

HTML

<span>
    <span class="my-font" aria-hidden="true">c</span>
    <span class="screen-reader">About me</span>
</span>

CSS

.screen-reader {
    position:absolute;
    top:-9999px;
    left:-9999px;
}

If it's just a decorative icon, it should better be served with CSS instead of HTML, for example with a pseudo-element: ::after(content:…; font:…;). Unfortunately, some screenreaders might read this content, too, and we can't apply WAI-ARIA in CSS, of course. So, depending on your situation, you might be "forced" to use markup with aria-hidden="true" instead.

If possible, you should also use a corresponding Unicode symbol (like , which is "U+2601 CLOUD") instead of a irrelevant character (like c).

If there is no corresponding character, you should make use of Unicode's Private Use Areas, which are code points that are left undefined, so you can define your own characters/symbols.

You might be interested in these posts:

While aria-hidden="true" works to hide the audible icon, it will still show up in the assistive technology's list of links and headings.

I'm still trying to find a way to hide them entirely, but it's tricky. To the OP, yes, aria-hidden="true" will hide them somewhat, but not entirely. Don't rely on it alone. Also, make sure you test with real users!

I came across this really good article: http://pictos.cc/articles/using-icon-fonts/

Best of luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!