Last updated: 5 May 2024

Tailwind CSS Screen Reader

The sr-only utility class in Tailwind CSS is used to hide content visually while keeping it accessible to screen readers.


Tailwind Screen Reader

The sr-only utility class in Tailwind CSS is used to hide content visually while keeping it accessible to screen readers. It allows you to include text or elements that are important for accessibility purposes but not intended to be seen by sighted users.

Applying Screen Reader Class

To apply the sr-only class to an element, simply add it to the desired HTML element.

Here's an example:

html
<button class="sr-only">Skip to main content</button>

In the above example, the <button> element is styled with the sr-only class, which visually hides it but ensures that screen readers can still access its content.

Responsive Screen Reader Class

Tailwind CSS also provides responsive variants for the sr-only class. You can use responsive classes to control the visibility of screen reader content at different breakpoints.

For example, md:sr-only applies the sr-only class starting from the medium breakpoint and above, making the element visible on smaller screens.

html
<button class="sr-only md:not-sr-only">Skip to main content</button>

In the above example, the <button> element is initially hidden with the sr-only class, but starting from the medium breakpoint and above, it becomes visible due to the md:not-sr-only class.

Usage Guidelines

It's important to use the sr-only class judiciously and only for content that is necessary for accessibility. Avoid hiding essential information or interactive elements from sighted users, as it may lead to a poor user experience.

Use the sr-only class sparingly and in situations where it enhances the accessibility of your website or application.

Tailwind Screen Reader Class Table

ClassProperties
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;

Windframe Tailwind blocks

landing page

Windframe is a drag and drop builder for rapidly building tailwind css websites and UIs

Start building stunning tailwind UIs! 

Build from scratch or select prebuilt tailwind templates