sr-only
Example
.sr-only {
display: none;
}.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-onlyon a link that keyboard users can focus but never see.
Key points
- The class uses a 1px clipped box, not
display: none,visibility: hiddenorhidden. - It includes
overflow: hidden,white-space: nowrapandclip-path: inset(50%)orclip. - Focusable elements using it become visible on focus.
Interview questions
What is the difference between sr-only and aria-hidden?
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?
sr-only or aria-label for icon buttons?Both work. sr-only text is translated by page translation tools more reliably than aria-label.