Applied Accessibility -10 Make Elements Only Visible to a Screen Reader by Using Custom CSS

Make Elements Only Visible to a Screen Reader by Using Custom CSS 


 CSS's magic can also improve accessibility on your page when you want to visually hide content meant only for screen readers. This happens when information is in a visual format (like a chart), but screen reader users need an alternative presentation (like a table) to access the data. CSS is used to position the screen reader-only elements off the visual area of the browser window.

here is div containing img
<div>
<img src="http://placehold.it/180" alt ="img to show "/>
</div>

img to show

And now we want to hide it from screen 

Here's an example of the CSS rules that accomplish this:

.sr-only {
position: absolute;
left: -10000px;
width: 1px;
height: 1px;
top: auto;
overflow: hidden;
}

now let's use it in our div
img to show

<div class="sr-only">
<img src="http://placehold.it/180" alt ="img to show "/>
</div>

Note 
The following CSS approaches will NOT do the same thing: display: none; or visibility: hidden; hides content for everyone, including screen reader users Zero values for pixel sizes, such as width: 0px; height: 0px; removes that element from the flow of your document, meaning screen readers will ignore it


source

Comments

Popular posts from this blog

ES6 : 5 Prevent Object Mutation

ES6: 1 Explore Differences Between the var and let Keywords

CSS Grid: Reduce Repetition Using the repeat Function