Skip to main content

Command Palette

Search for a command to run...

How to hide content from the screen and not from screen readers

Published
•1 min read
How to hide content from the screen and not from screen readers
D

I am 17 years old and a young passionate and self-taught frontend web developer and have an intention to become a successful developer. I usually write about JavaScript and Web Development and share some tips in the articles.

As a developer, we tend to hide things using display: none and visibility: hidden.

This works perfectly fine actually to hide elements from the screen. But, it also hides the things on the screen which also includes a screen reader.

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

The A11Y Project has made available a useful CSS for hiding content from screen readers.

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

Provide a name for the class visually-hidden to the element you want to hide from the screen but not from screen readers.

Thank you for reading

I hope this article was worth reading. Please do consider a like and share it with your colleagues and friends.

Consider buying me a coffee

Let's connect

Thanks for reading!

More from this blog

D

Dhairya Shah

119 posts