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?
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.
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).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With