Visually hidden text is content that is removed from the visual presentation of a page but remains in the accessibility tree, so screen readers and other assistive technologies still announce it. In web accessibility, the technique supplies context that sighted users infer from layout, icons or color, for example the words “Open menu” behind a hamburger icon or “opens in a new tab” after a link.
Developers usually apply it through a utility class named sr-only or visually-hidden, and the result is often called screen-reader-only text. The technique is simple, but it depends on precise CSS: the wrong hiding method either removes the content from assistive technologies as well or leaves visual artifacts on the page.
How the visually hidden pattern works
Visually hidden text works by shrinking an element to a single pixel and clipping it instead of removing it from rendering. Browsers build the accessibility tree from rendered content, so an element that is clipped but still displayed keeps its accessible name and reading position, while display: none or visibility: hidden removes it from both the screen and the tree.
A robust utility class combines several declarations, each of which closes a specific gap. The table below explains the purpose of each property in the widely used pattern.
| CSS declaration | Purpose | What breaks without it |
|---|---|---|
position: absolute | Takes the element out of the layout flow | Surrounding content shifts |
width: 1px; height: 1px | Reduces the box to a minimal size | Text occupies visible space |
overflow: hidden | Hides content beyond the tiny box | Text spills out visibly |
clip-path: inset(50%) | Clips the remaining pixel to nothing | A one-pixel dot may appear |
white-space: nowrap | Prevents words from wrapping vertically | Some screen readers merge words |
margin: -1px; border: 0; padding: 0 | Removes residual spacing | Scrollbars or layout gaps appear |
Older versions of the pattern use the deprecated clip: rect(0 0 0 0) property, which still works in current browsers and is often kept alongside clip-path for compatibility. A width or height of zero is avoided on purpose, because some screen readers skip elements with no dimensions.
Visually hidden text compared with other hiding methods
The defining property of visually hidden text is that it hides content from sight but not from assistive technologies. Other hiding methods behave differently, and choosing the wrong one is a frequent cause of accessibility defects found in an accessibility audit.
| Technique | Visible on screen | Exposed to screen readers | Typical use |
|---|---|---|---|
| Visually hidden class | No | Yes | Extra context for assistive technologies |
| display: none | No | No | Closed menus, inactive tabs |
| hidden attribute | No | No | Content not yet relevant |
| visibility: hidden | No | No | Hiding while keeping layout space |
| aria-hidden=”true” | Yes | No | Decorative icons and duplicates |
| opacity: 0 | No | Yes, but still focusable | Animations; risky for hiding |
| Off-screen positioning | No | Yes | Legacy alternative; can cause scroll issues |
Visually hidden text and aria-label solve related problems. An aria-label attribute overrides the accessible name of an element, while visually hidden text adds real DOM content that browser translation tools translate, that users can find with in-page search in some contexts, and that remains readable when styles fail to load.
Common uses in accessible interfaces
Visually hidden text is most valuable where visual context replaces words. Sighted users understand an icon, a column position or a color change at a glance, whereas a screen reader user hears only what the markup provides.
- Icon-only buttons, such as a magnifying glass that needs the label “Search”.
- Ambiguous links such as repeated “Read more” links, extended with the article title.
- Form hints and headings that structure a page for navigation without adding visual clutter.
- Status descriptions in data tables, for example “current page” in pagination.
- Skip links, which use a variant that becomes visible when it receives keyboard focus.
The skip link case requires a focusable variant, often called visually-hidden-focusable, which removes the clipping on :focus. Without it, a keyboard user would tab to an invisible but focused element, which violates the expectation that focus is always visible.
Guidelines and design decisions
Visually hidden text supports several WCAG success criteria, including 1.1.1 Non-text Content, 2.4.4 Link Purpose (In Context) and 1.3.1 Info and Relationships. It is a means of conformance, not a requirement in itself, and the Web Accessibility Initiative treats it as one of several valid techniques.
The decision table below helps choose between visually hidden text and alternative approaches in common situations.
| Situation | Recommended technique | Reason |
|---|---|---|
| Icon button with no text | Visually hidden text or aria-label | Gives the control an accessible name |
| Repeated “Read more” links | Visually hidden text inside the link | Makes each link purpose unique |
| Purely decorative icon | aria-hidden=”true” | Avoids redundant announcements |
| Dynamic status message | ARIA live region | Announces changes without focus moves |
| Label needed by all users | Visible text | Helps cognitive and voice-control users |
The last row reflects an important principle: if the information helps everyone, show it. Voice-control users say what they see, so a hidden label that differs from the visible text breaks commands; WCAG 2.5.3 Label in Name requires the accessible name to contain the visible label.
Pitfalls and testing
Visually hidden text fails when it is inaccurate, excessive or misplaced. Long hidden passages make screen reader navigation slower, and text that contradicts the visual interface confuses users who combine sight with a screen reader, such as many people with low vision.
- Overuse: hiding instructions that sighted users would also benefit from.
- Focusable hidden content: links or buttons inside a clipped container that receive focus invisibly.
- Stale text: hidden labels that are not updated when the visual state changes.
- Search engine misuse: keyword stuffing in hidden text, which search engines may treat as spam.
Testing requires real assistive technologies. Inspecting the accessibility tree in browser developer tools confirms that the text is exposed, and listening with NVDA, JAWS or VoiceOver confirms that it is announced in the right place. Automated tools such as WAVE or Pa11y detect missing names but cannot judge whether hidden text is meaningful and accurate.
Stripped to the essentials
Some websites show only a picture where words would normally be, such as a little magnifying glass for search. People who use a screen reader, a program that reads the page aloud, cannot see that picture.
Visually hidden text is a quiet label meant only for the ear. It is written into the page but tucked away so it does not appear on screen. The screen reader finds it and says “Search”, while everyone else sees the same clean design. The key idea is simple: nobody loses information, whether they read the page with their eyes or listen to it.
Where it is applied
A municipal website lists twenty news items, each ending with a link that says “Read more”. During an accessibility audit, a tester using NVDA opens the links list and hears twenty identical entries, with no way to tell which story each link opens.
The development team adds a visually-hidden span inside every link, so the accessible name becomes, for example, “Read more about the new recycling schedule”. The visual design stays unchanged, the links pass WCAG 2.4.4, and a follow-up test shows that screen reader users find a specific article in seconds instead of opening links one by one. The team also adds the same pattern to the icon-only share buttons in the footer.