DEV Community

Cover image for Tailwind CSS tutorial #32: Screen Readers
Shubhi✨
Shubhi✨

Posted on

Tailwind CSS tutorial #32: Screen Readers

In the article, we will go into detail on how to use Screen Readers.

Screen Readers

Format

sr-only

Tailwind Class CSS Property
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;}

Basic usage

Screen-reader-only elements

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

Undoing screen-reader-only elements

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:

Code

<ul class="container mx-auto divide-y divide-gray-400 divide-dotted" style="font-family: Raleway">
  <li class="flex items-center justify-between px-4 py-2">
    <div class="flex flex-col items-center justify-center">
        <div class="w-1/2">
          <img class="w-24" src="http://pixelprowess.com/i/powship.svg" alt="POW Logo">
          <p class="sr-only lg:not-sr-only text-gray-500 text-2xl text-blue-300 leading-none">Lorem ipsum dolor sit amet consectetur adipisicing elit impedit officia fugiat mollitia alias ex quas modi.</p>
          <p>Voluptatibus ad distinctio, modi sed praesentium nobis quas non aperiam, recusandae illum, animi sit labore cumque in obcaecati cum laboriosam voluptas consectetur. Voluptate voluptates porro aliquid ut maiores, quidem rem!</p>
        </div>
    </div> 
    <div class="ml-5 text-right">
      <div class="text-xs font-semibold inline-block font-mono whitespace-nowrap px-2 py-1 rounded text-white bg-pink-500 rounded-2 mb-1">sr-only</div>
      <div class="text-xs font-semibold inline-block font-mono whitespace-nowrap px-2 py-1 rounded text-white bg-pink-500 rounded-2">not-sr-only</div>
    </div>
  </li>
</ul>

Enter fullscreen mode Exit fullscreen mode

Full code:
The overall code will be attached to repo link.

Overall Output
Image description

Resources:
tailwind.css

Thank you for reading :), To learn more, check out my blogs on Flex Direction, Hackathons and Flex Wrap.
If you liked this article, consider following me on Dev.to for my latest publications. You can reach me on Twitter.

Keep learning! Keep coding!! 💛

Top comments (0)