Skip to main content

Overview

Visually Hidden hides content visually while keeping it accessible to screen readers. This is useful for providing additional context or labels that don’t need to be visible but should be announced by assistive technologies.

Features

  • Hides content visually using CSS
  • Content remains accessible to screen readers
  • Content remains in the document flow

Installation

Anatomy

API Reference

Root

Hides content visually while keeping it accessible to screen readers.
React.ReactNode
The content to be visually hidden.

Examples

Form Label

Icon Button Label

Using VISUALLY_HIDDEN_STYLES

The component also exports the CSS styles used to visually hide content, which you can use directly:

How It Works

The component uses a combination of CSS properties to hide content visually:
  • position: absolute - Removes from normal document flow
  • width: 1px and height: 1px - Makes element nearly invisible
  • padding: 0 and margin: -1px - Minimizes space
  • overflow: hidden - Hides any overflow
  • clip: rect(0, 0, 0, 0) - Clips the element
  • whiteSpace: nowrap - Prevents wrapping

When to Use

Use Visually Hidden when you need to:
  • Provide additional context for screen readers
  • Add labels to form inputs that don’t need to be visible
  • Include descriptive text for icon-only buttons
  • Create skip links for keyboard navigation
  • Provide status messages that are announced but not shown

Accessibility

This technique is widely used and recommended for hiding content visually while keeping it accessible. It’s based on the approach used by Bootstrap and other accessibility-focused libraries.