liveBook · Manning

Visually hidden text

As explained in Architecting Accessibility

Visually hidden text is text that remains available to assistive technologies while being visually concealed from sighted users.

A link that opens a new window can surprise someone using a screen reader. Visually hidden text can give that person a warning while an icon provides a visual cue. Do not use `display:none` for the warning: it hides the text from everyone. section 5.4

<a href="/anotherpage" target="_blank">
  Dog therapists in your area.
  <span class="visually-hidden">(opens in new window)</span>
  <img src="images/new-win.png" alt="" aria-hidden="true" class="new-win">
</a>

The link includes a visually hidden warning and a decorative icon. The icon has empty alternative text so it does not repeat the warning. section 5.4

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
  /*margin: -1px; <-- fallback for older browsers*/
}

The CSS reduces the warning to a clipped 1-pixel area while keeping it in the accessibility tree. section 5.4

An icon is useful only if sighted users understand it. When possible, put the warning in visible text instead: everyone gets the same cue, with less code. section 5.4

How Architecting Accessibility covers it

How deep it goes
Defines the technique, gives an HTML example and CSS class, and cautions against `display:none`; stops short of broader applications.
Examples
Shows a new-window link with a hidden warning and decorative image, plus the CSS that clips the warning.
What you can do after
Apply it via a CSS class to add an assistive technology warning to a new-window link.
How it connects
Connects link warnings to screen readers, the accessibility tree, alternative text, and decorative images.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting Accessibility. The section links point to the parts of the book it draws on.