Course contentsShow
← Web Development
Lesson 1127 of 2,98220. Screen Readers and Assistive TechnologyFree lesson

The CSS Visually Hidden Pattern

The standard CSS technique to hide content visually while preserving screen reader access and focus behavior.

The CSS Visually Hidden Pattern

You'll learn the standard CSS technique to hide content from sight while keeping it accessible to screen readers and keyboard users.

The Problem It Solves

Sometimes you need text that screen reader users hear but sighted users don't see—like a "Close" button that only shows an ✕ icon, or a "Search" button with just a magnifying glass. Using display: none or visibility: hidden would hide the content from everyone, including assistive technology.

The Visually Hidden Technique

The solution is a specific set of CSS properties that removes content from the visual flow while preserving it in the accessibility tree:

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

This pattern:

  • Shrinks the element to 1×1 pixel
  • Positions it absolutely so it doesn't affect layout
  • Clips it to essentially nothing
  • Hides overflow so content doesn't spill out
  • Prevents wrapping that might expand the box

When to Use It

Perfect for:

  • Descriptive button text when only an icon shows: <button><span class="visually-hidden">Close</span>✕</button>
  • Form labels when design shows placeholder text instead
  • Skip links that appear only on keyboard focus
  • Extra context for screen reader users

The Magic

Unlike display: none, this keeps the content in the DOM's accessibility tree. Screen readers find it and announce it. Focusable elements inside can still receive keyboard focus (though you'll often combine this with :focus styles to reveal them).

Key Takeaway: The visually hidden pattern hides content from sight while keeping it fully accessible to screen readers and keyboard navigation—essential for inclusive icon buttons, labels, and navigation aids.