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:
<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.
<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
Class | Properties |
---|---|
sr-only | position: 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-only | position: static; width: auto; height: auto; padding: 0; margin: 0; overflow: visible; clip: auto; white-space: normal; |
Windframe Tailwind blocks
Windframe is a drag and drop builder for rapidly building tailwind css websites and UIs