# Screen reader text

Hide text visually while keeping it in the accessibility tree.

- ID: sr-only
- Type: utility
- Canonical: /reference/sr-only
- Version: 2.1.8
- Source revision: 09fc2350ea80ed137ba7ca62c8e5926744b5a5dc (revision)
- Source: packages/preset/src/utilities.css
- Content digest: 2eacbcaa43ee5c3564d9a6ff26b04c5a890678c1c2a8e385ee49b6e91cd5747b
- Semantic digest: 83962260d6d56817dd052d2beebf7999a75804215dac050c47b26353145c099a
- Language: en

> Syntax placeholders illustrate declaration shapes; they are not an exhaustive grammar for valid values. Examples use the current preset.

<a id="overview"></a>

## Classes

| Class | Declarations |
| --- | --- |
| `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;` |

Use this class for text that should remain available to assistive technology. It is not a way to disable an element or remove it from keyboard navigation.

<a id="visual-and-accessible"></a>

## Visual clipping and accessible naming are separate

`sr-only` takes its element out of normal flow, gives it a 1px box and clips its paint. It does not apply `display: none`, `visibility: hidden` or `aria-hidden`. Text can therefore still contribute to an accessible name.

**Clipped text can still name a visible control**

The arrow has aria-hidden="true". The label text is visually clipped by sr-only and supplies the link’s accessible name. The link itself stays visible and focusable.

- The link contains an arrow excluded from accessible-name calculation and a span containing Read the utility definition.
- The span uses the actual sr-only preset: absolute positioning, a 1px box, hidden overflow and clipping. It remains in the DOM without aria-hidden.
- The visible link still occupies a 40px square and shows the arrow. Its accessible role is link and its name is Read the utility definition.
- The two branches are representations of the same control, not sequential operations. Hiding an ancestor from the accessibility tree would also hide its descendants.

Put the class on the label text inside a control. Keep the control itself visible and focusable. An icon marked `aria-hidden="true"` stays out of the name, leaving the text to describe the action.

Do not put a focusable control inside an always-clipped region: keyboard users could reach a control they cannot see. A skip link needs its own visible-on-focus styling; the preset does not provide a `not-sr-only` reversal utility.

An ancestor that removes the subtree from the accessibility tree still removes this text. `sr-only` cannot counteract `hidden`, `display: none` or `aria-hidden="true"` on an ancestor. Test the resulting role and name in the actual control.

See [accessible names](https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/).

<a id="examples"></a>

## Usage

Name an icon-only link that opens the utility definition below.

```html
<a href="#customize">
  <span aria-hidden="true">↓</span>
  <span class="sr-only">Read the utility definition</span>
</a>
```

```css disclosure=generated-css
@layer utilities{.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}}
```

The link’s accessible name is “Read the utility definition”; the arrow is excluded from that name.

<a id="customize"></a>

## Customize

The preset defines these classes with `@utility`. Define the same name in your stylesheet to replace it.

```css
@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;
}
```

See [utility definitions](/reference/directives/definitions).

## Related reference

- [directives/definitions](/reference/directives/definitions.md)
