Tailwind_Class
::
The_Power_of_sr-only
Why hidden text is essential for accessibility and how we use it to provide raw data for screen readers on our interactive maps.
Visual design often requires us to hide certain elements to keep the UI clean. However, “hidden” shouldn’t mean “non-existent.” This is where the Tailwind class sr-only becomes a game-changer.
Screen_Readers
What is sr-only?
The sr-only utility hides an element visually but keeps it fully accessible to screen readers. Unlike display: none or hidden, which remove the element from the accessibility tree entirely, sr-only ensures that visually impaired users still get the full context of your page.
Real-world use case: interactive maps
A perfect example is our Madeira Travel_Log. While sighted users interact with the visual map, screen readers need a structured alternative to understand the data points.
Under the map, we provide a raw list of coordinates and descriptions wrapped in a div with the sr-only class.
Quick test
If you want to see the “invisible” data on our Madeira post, simply open the browser inspector, find the section under the map, and remove the
sr-onlyclass. The raw data list will instantly appear on your screen.
Beyond static: no-JS fallback
One might argue that if a user has JavaScript disabled, they won’t see the interactive map at all. In that case, hiding the data with sr-only might not be ideal—they actually need to see that text to get any value from the post.
A smarter approach is to use a dynamic class or a “No-JS” fallback. Imagine a logic where you only apply sr-only if JavaScript is active. If JS fails to load, the map remains hidden, but the raw data list stays visible to everyone, providing a functional baseline.
Data layer: JSON-LD for SEO
To complete the circle, we don’t just stop at accessibility for humans. We also provide the same data points in a structured JSON-LD format (using Schema.org).
While sr-only serves people using screen readers, JSON-LD serves search engine crawlers. By defining each marker as a Place with specific GeoCoordinates, we ensure that our map data is semantically clear for Google and other bots.
- SEO Efficiency: It explicitly tells search engines what locations are mentioned on the page.
- Precision: We keep our data clean and consistent across both the UI and the metadata (using that 5-decimal precision).
- Robustness: Even if the interactive map fails to load, the core data is still present in the page’s source code in a machine-readable format.
Final thought
By combining interactive maps for visual storytelling, sr-only for accessibility, and JSON-LD for search engines, you create a truly professional web experience.
Don’t just build for the eyes—build for the entire web ecosystem.