Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 28, 2022 04:32 pm GMT

A11Y 101: Hiding content

We developers tend to hide elements by using display: none or visibility: hidden.

And this works perfectly fine actually to hide elements from the screen.
However, be aware this does precisely what we tell it. It hides things from the screen, which includes screen readers!

Hiding from screens, but not screen readers

Let's see what it takes to hide elements from the screen, but not screen readers.

An example of this is: hiding the label for the search field.

We have to be careful about which CSS we want to use to achieve this behavior.

I love to use the CSS provided by the A11Y project as it's super complete and up to date.

.visually-hidden {  clip: rect(0 0 0 0);  clip-path: inset(50%);  height: 1px;  overflow: hidden;  position: absolute;  white-space: nowrap;  width: 1px;}

If you add this class to any element, It will be removed from the screen but announced by screen readers.

Conclusion

We have to be careful when we hide elements from the screen. Screen readers might not be able to read the information anymore if we entirely hide the element.

Using the provided CSS code, we can achieve the effect we want.

Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter


Original Link: https://dev.to/dailydevtips1/a11y-101-hiding-content-35kj

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To