# Screen readers Visually hidden content, live regions, toasts, alt text and SVG. ## Visually hidden content The canonical `.sr-only` pattern hides content visually while keeping it in the accessibility tree: ```css .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; } ``` Use `1px` boxes, not `0`, because some screen readers skip zero-sized elements. `white-space: nowrap` stops words being read as one run-together string. Never `display: none` or `visibility: hidden`, which remove the content from assistive tech entirely. Tailwind ships this as `sr-only`. The skip-link recipe is in [focus-and-keyboard.md](focus-and-keyboard.md). Use it for context sighted users get visually: `Opens in new tab`, table captions or an icon-only control's label where `aria-label` isn't an option. ## Choosing how to announce a change Work down this list and stop at the first match: 1. **Focus moves there anyway**, as with an opened modal or the first invalid field. Nothing extra needed; the focus move is the announcement. 2. **Tied to a specific control**, such as a field error or character count: `aria-describedby` on the control, announced with the field. 3. **Non-urgent, not tied to a control**, such as a toast, "Saved", a result count or a loading state: a polite live region, `role="status"`. 4. **Urgent and not tied to a control**, such as a form-level failure or session expiry: `role="alert"`. ## Live regions | Mechanism | Politeness | Use for | | --- | --- | --- | | `role="status"` (= `aria-live="polite"` + `aria-atomic="true"`) | Waits for a pause | Toasts, "Saved", result counts, loading updates | | `role="alert"` (= `aria-live="assertive"` + `aria-atomic="true"`) | Interrupts immediately | Errors and urgent problems only | Rules for reliable announcements: - For repeated polite updates, keep a stable empty region in the DOM before changing its text. Inserting a new polite region with its content is announced inconsistently. - Dynamically inserted `role="alert"` content is usually announced, but behavior varies. Test the target browser and screen-reader combinations. - Default to polite. `assertive` interrupts whatever the user was reading. - Keep messages short and self-contained. `aria-atomic="true"` re-reads the whole region on change. - Never move focus to a toast. Announce it and leave focus where the user is working. ```tsx // Region rendered from the start, message injected later