Screen Readers

Tailwind CSS version

v1.1.0+

Utilities for improving accessibility with screen readers.

Class reference

Class
Properties
.sr-onlyposition: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;
.not-sr-onlyposition: static; width: auto; height: auto; padding: 0; margin: 0; overflow: visible; clip: auto; white-space: normal;

Usage

Use sr-only to hide an element visually without hiding it from screen readers:

  1. <a href="#">
  2. <svg><!-- ... --></svg>
  3. <span class="sr-only">Settings</span>
  4. </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:

  1. <a href="#">
  2. <svg><!-- ... --></svg>
  3. <span class="sr-only sm:not-sr-only">Settings</span>
  4. </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:

  1. <a href="#" class="sr-only focus:not-sr-only">
  2. Skip to content
  3. </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:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. // ...
  5. - accessibility: ['responsive', 'focus'],
  6. + accessibility: ['responsive', 'focus', 'hover', 'active'],
  7. }
  8. }

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:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + accessibility: false,
  6. }
  7. }

← Stroke Width   Typography →