Visually hidden
Text for screen readers only: clipped to a single pixel, still read aloud and still in the tab order.
Examples
Extra context
The links read "Edit Atlas" and "Edit Harbor" to a screen reader; sighted users see "Edit".- Atlas Edit Atlas
- Harbor Edit Harbor
Names for visual options
The swatch picker shows colours; .sr-only gives each radio a name a screen reader can read.Anatomy
.sr-only | Any element. Absolutely positioned, 1×1px, clipped and unwrapped, so it takes no space and draws nothing. |
Accessibility
- Use it to add context the visual layout already gives (which row a button acts on), not to hide content from everyone. For that, use
hidden. - Don't put it on a focusable element: it stays in the tab order but its focus ring is clipped away. Hide the text inside the control instead.
- Prefer
aria-labelfor naming a single control;.sr-onlyis for text inside the flow of a sentence or a list.