Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appropriate way to hide icons from screen readers

In my web application, I have made myself a font that consists solely of icons. I use these icons to complement titles and sub titles within the application and make it more visually appealing.

However, screen readers like JAWS read this out and it makes for an unpleasant experience for users of screen readers.

For instance the character c displays an image of a cloud. I use it in this way to complement for instance a header such as <h1>:

<span class="my-font">c</span>

Now I would like for screen readers to completely ignore this as this is just complementing an existing title and not adding any new meaning to what's on the page. Through my research I have found two possibilities:

aria-hidden="true" or role="presentation"

I'm just not sure which one of these (or perhaps both) are suitable to what I am trying to achieve.

like image 752
karancan Avatar asked Apr 01 '13 23:04

karancan


People also ask

Can screen readers read hidden labels?

Screen readers generally ignore anything with display: none, therefore it is not read out to screen readers. There are various ways of having things hidden visually or non-visually, so we'll run through the cases and techniques for each.

Does visibility hidden hide from screen readers?

Methods to Hide from Screen Readers To hide text from a screen reader and hide it visually use the hidden attribute. You can also use CSS to set display: none or visibility: hidden to hide an element from screen readers and visually.

How do I hide text and make it accessible by screen reader?

visibility: hidden; and/or display:none; These styles will hide text from all users. The text is removed from the visual flow of the page and is ignored by screen readers.

Does visibility hidden affect accessibility?

The main reason the visibility: hidden rule isn't just about visual visibility is because it affects the elements visibility to assistive technology as well. When we apply visibility: hidden to an element, it also removes it from the accessibility tree, which makes it invisible to technologies like screen readers.


2 Answers

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;
}
like image 145
Daniel Imms Avatar answered Sep 16 '22 12:09

Daniel Imms


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:

  • css-tricks.com: HTML for Icon Font Usage
  • nimbupani.com: Markup-free icon fonts using unicode-range
like image 24
unor Avatar answered Sep 17 '22 12:09

unor