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. 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

Build modern projects using Bootstrap 5 and Contrast

Trying to create components and pages for a web app or website from scratch while maintaining a modern User interface can be very tedious. This is why we created Contrast, to help drastically reduce the amount of time we spend doing that. so we can focus on building some other aspects of the project.

Contrast Bootstrap PRO consists of a Premium UI Kit Library featuring over 10000+ component variants. Which even comes bundled together with its own admin template comprising of 5 admin dashboards and 23+ additional admin and multipurpose pages for building almost any type of website or web app.
See a demo and learn more about Contrast Bootstrap Pro by clicking here.

ad-banner