Accessibility/SEO Friendly CSS Hiding

Avatar of Chris Coyier
Chris Coyier on (Updated on )
.screen-reader-text {
  position: absolute;
  top: -9999px;
  left: -9999px;
}

This class can remove an item from the page, taking it out of flow and doesn’t cause overflow scrolling.

It’s better than display: none; or even visibility: hidden; when the goal is to hide the element visually but leave it accessible for screen readers.

Snook has a walkthrough of a more robust class taking into account more situations.

.element-invisible {
  position: absolute !important;
  height: 1px; width: 1px; 
  overflow: hidden;
  clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
  clip: rect(1px, 1px, 1px, 1px);
}

WordPress uses an even more robust class taking into account showing the element should it have focus.

.screen-reader-text {
  border: 0;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  word-wrap: normal !important;
}
.screen-reader-text:focus {
  background-color: #eee;
  clip: auto !important;
  clip-path: none;
  color: #444;
  display: block;
  font-size: 1em;
  height: auto;
  left: 5px;
  line-height: normal;
  padding: 15px 23px 14px;
  text-decoration: none;
  top: 5px;
  width: auto;
  z-index: 100000; /* Above WP toolbar. */
}