sr-only

Term side of the Card.
Topic: Accessible Elements
Unit title: sr-only
Categories: Concept
Explanation side of the Card

Explanation: 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.

Example

Wrongcss
.sr-only {
  display: none;
}
Rightcss
.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.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy