Web Accessibility & WCAG (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
The `.sr-only` (Screen Reader Only) CSS Pattern.
senior LevelCode ExampleSystem Design
In Simple Words: Hiding text visually from the screen while keeping it fully announced in the Accessibility Tree:
css
/* ❌ DO NOT USE display: none or visibility: hidden (removes from accessibility tree!) */
/* ✅ The Standard Accessible Screen Reader Utility */
.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;
}
Allows sighted users to see a visual icon (magnifying glass) while screen readers read <span class="sr-only">Search catalog</span>.