Screenreaders
Use screenreader utilities to hide elements on all devices except screen readers.
Hide an element to all devices except screen readers with .sr-only. Combine .sr-only with .sr-only-focusable to show the element again when it’s focused (e.g. by a keyboard-only user). Can also be used as mixins.
<a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>
// Usage as a mixin
.skip-navigation {
@include sr-only;
@include sr-only-focusable;
}
<p><strong>Screenreaders</strong></p>
<p>Use screenreader utilities to hide elements on all devices except screen readers.</p>
<p>Hide an element to all devices <strong>except screen readers</strong> with <strong>.sr-only</strong>. Combine <strong>.sr-only</strong> with <strong>.sr-only-focusable</strong> to show the element again when it’s focused (e.g. by a keyboard-only user). Can also be used as mixins.</p>
<pre class="mdl-code">
<a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>
</pre>
<pre class="mdl-code">
// Usage as a mixin
.skip-navigation {
@include sr-only;
@include sr-only-focusable;
}
</pre>
// Only display content to screen readers
//
// See: https://a11yproject.com/posts/how-to-hide-content/
// See: https://hugogiraudel.com/2016/10/13/css-hide-and-seek/
@mixin sr-only() {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px; // Fix for https://github.com/twbs/bootstrap/issues/25686
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
// Use in conjunction with .sr-only to only display content when it's focused.
//
// Useful for "Skip to main content" links; see https://www.w3.org/TR/2013/NOTE-WCAG20-TECHS-20130905/G1
//
// Credit: HTML5 Boilerplate
@mixin sr-only-focusable() {
&:active,
&:focus {
position: static;
width: auto;
height: auto;
overflow: visible;
clip: auto;
white-space: normal;
}
}