Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Last active March 22, 2018 19:41
Show Gist options
  • Save sethdavis512/e2bb86a751cb5b5f0abaf7d30b40bff6 to your computer and use it in GitHub Desktop.
Save sethdavis512/e2bb86a751cb5b5f0abaf7d30b40bff6 to your computer and use it in GitHub Desktop.
Visually hidden to sighted users. Still able to be read by screen readers.
/*
* Hide only visually, but have it available for screen readers:
* https://snook.ca/archives/html_and_css/hiding-content-for-accessibility
*
* 1. For long content, line feeds are not interpreted as spaces and small width
* causes content to wrap 1 word per line:
* https://medium.com/@jessebeach/beware-smushed-off-screen-accessible-text-5952a4c2cbfe
*/
.visuallyhidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
white-space: nowrap; /* 1 */
}
/*
* Extends the .visuallyhidden class to allow the element
* to be focusable when navigated to via the keyboard:
* https://www.drupal.org/node/897638
*/
.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus {
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
white-space: inherit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment