Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide CSS generated content from screen readers without HTML markup?

How would one hide CSS certain generated content (used for pure styling) from screen reader? Is it possible without using HTML hacks like aria-hidden?

E.g. I use code content: '·'; for separating stuff. I've checked facebook & other big players but they all seem to use spans with aria-hidden:

<span aria-hidden="true">·</span>

Does it mean it’s not possible currently?

like image 575
Runnick Avatar asked Nov 22 '17 15:11

Runnick


People also ask

How do I hide content from screen reader?

To hide text from a screen reader and display it visually, use the aria-hidden attribute and set it to true. 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 content but still accessible to assistive technology like a screen reader?

The conventional way is to use CSS ( display:none; and visibility:hidden; ) or the HTML 5 `hidden` attribute. These properties hide elements not only on the screen, but also for screen reader users. Thus, these elements will not be visible nor vocalized by Assistive technologies (AT).

Can screen readers see hidden elements?

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.


1 Answers

For future references, note that according to CSS 3 documentation:

Generated content should be searchable, selectable, and available to assistive technologies. The content property applies to speech and generated content must be rendered for speech output.

It's also stated that :

If the pseudo-element is purely decorative and its function is covered elsewhere, setting alt to the empty string can avoid reading out the decorative element.

This concernes ::before and ::after pseudo-elements; alternative text might be indicated after a /:

.expandable::before {
  content: "\25BA" / ""; 
}

For CSS2, you may use unpronounceable UTF-8 elements in order to be sure that the elements won't be announced.

For instance, when you use the code:

.bullet {
    content: "\2022";
}

\2022 (bullet : •) announces "bullet" with NVDA while another code like \2023 (triangular bullet : ‣) announces nothing

like image 162
Adam Avatar answered Oct 19 '22 01:10

Adam