Screen Readers
- Tailwind CSS version
- v1.1.0+
Utilities for improving accessibility with screen readers.
Usage
Use sr-only
to hide an element visually without hiding it from screen readers:
<a href="#">
<svg><!-- ... --></svg>
<span class="sr-only">Settings</span>
</a>
Use not-sr-only
to undo sr-only
, making an element visible to sighted users as well as screen readers. This can be useful when you want to visually hide something on small screens but show it on larger screens for example:
<a href="#">
<svg><!-- ... --></svg>
<span class="sr-only sm:not-sr-only">Settings</span>
</a>
By default, responsive
and focus
variants are generated for these utilities. You can use focus:not-sr-only
to make an element visually hidden by default but visible when the user tabs to it — useful for "skip to content" links:
<a href="#" class="sr-only focus:not-sr-only">
Skip to content
</a>
Customizing
Responsive and pseudo-class variants
By default, only responsive and focus variants are generated for accessibility utilities.
You can control which variants are generated for the accessibility utilities by modifying the accessibility
property in the variants
section of your tailwind.config.js
file.
For example, this config will also generate hover and active variants:
// tailwind.config.js
module.exports = {
variants: {
// ...
- accessibility: ['responsive', 'focus'],
+ accessibility: ['responsive', 'focus', 'hover', 'active'],
}
}
Disabling
If you don't plan to use the accessibility utilities in your project, you can disable them entirely by setting the accessibility
property to false
in the corePlugins
section of your config file:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ accessibility: false,
}
}