# sr-only

> The `sr-only` accessible practice in CSS is used to hide content visually while keeping it available for screen readers, enhancing accessibility.

## How do I hide text visually but keep it for screen readers?

The CSS utility class that hides content visually but keeps it available to screen readers, using a 1px clipped box instead of `display: none`. Used for extra labels, such as text for icon-only buttons or skip links.

- Topic: Accessible Elements
- Type: concept

## Example

Wrong:

```css
.sr-only {
  display: none;
}
```

Right:

```css
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
```

A clipped 1px box stays in the accessibility tree, unlike `display: none`.

## Common mistakes

- Hiding text with `display: none`, which hides it from screen readers too.
- Using `sr-only` on a link that keyboard users can focus but never see.

## Key points

- The class uses a 1px clipped box, not `display: none`, `visibility: hidden` or `hidden`.
- It includes `overflow: hidden`, `white-space: nowrap` and `clip-path: inset(50%)` or `clip`.
- Focusable elements using it become visible on focus.

## Interview questions

### What is the difference between `sr-only` and `aria-hidden`?

They do opposite jobs: `sr-only` hides from the eye but not screen readers; `aria-hidden` hides from screen readers but not the eye.

### Should I use `sr-only` or `aria-label` for icon buttons?

Both work. `sr-only` text is translated by page translation tools more reliably than `aria-label`.

## Related cards

- [\[aria-hidden\]](https://wonderium.dev/a11y/aria-hidden.md)
- [Skip Link](https://wonderium.dev/a11y/skip-link.md)
- [clip-path](https://wonderium.dev/css/clip-path.md)
- [display](https://wonderium.dev/css/display.md)
- [\[aria-label\]](https://wonderium.dev/a11y/aria-label.md)

---

- Level: [Accessibility](https://wonderium.dev/a11y.md)
- HTML version: https://wonderium.dev/a11y/sr-only
- Last updated: 2026-11-25
