Bootstrap - Bootstrap Visually Hidden Helpers

Bootstrap Visually Hidden Helpers are utility classes used to hide content visually while keeping it available to screen readers and other assistive technologies. They are particularly useful when developing accessible websites where some information is necessary for users who rely on assistive technology but would create unnecessary visual clutter for users who can see the page.

1. What Are Visually Hidden Helpers?

Normally, when an HTML element is hidden using CSS such as display: none, the element is removed from the visual page and is generally ignored by screen readers. However, there are situations where you want the content to remain available to screen readers without displaying it on the screen.

Bootstrap provides the .visually-hidden utility for this purpose.

For example:

<p class="visually-hidden">
  This information is available to screen reader users.
</p>

The paragraph will not appear visually on the webpage, but assistive technologies can still access its content.

2. Why Are They Important?

Accessibility is an important part of modern web development. A website should provide meaningful information to users with different abilities and different methods of interacting with websites.

Some visual elements may already communicate information through icons, colors, or graphical indicators. A screen reader user may not receive the same information unless additional text is provided.

For example:

<button type="button">
  <span class="visually-hidden">Close</span>
</button>

A sighted user might understand that the button closes a window from its visual appearance. A screen reader user, however, needs an accessible name to understand the button's purpose. The visually hidden text provides that additional information.

3. The .visually-hidden Class

The primary Bootstrap utility is:

.visually-hidden

It can be applied to text or other content that should remain accessible to assistive technologies but should not normally be visible.

Example:

<h2>
  Products
  <span class="visually-hidden">available in this category</span>
</h2>

Visually, the user sees only "Products", while a screen reader can also interpret the additional hidden information.

This approach is useful when additional context improves accessibility without needing to add visible text to the interface.

4. .visually-hidden-focusable

Bootstrap also provides the .visually-hidden-focusable utility. This class is designed for content that should normally remain visually hidden but should become visible when it receives keyboard focus.

A common example is a skip link.

<a class="visually-hidden-focusable" href="#main-content">
  Skip to main content
</a>

The link remains hidden during normal browsing. When a keyboard user focuses on it, it can become visible and provide a convenient way to skip repetitive navigation and move directly to the main content.

This is especially useful for users who navigate websites using the keyboard instead of a mouse.

5. Difference Between .visually-hidden and .visually-hidden-focusable

The two utilities serve different purposes.

.visually-hidden is intended for content that should remain visually hidden while still being accessible to assistive technologies.

<span class="visually-hidden">
  Additional information
</span>

.visually-hidden-focusable is intended for content that should normally be hidden but should become visible when it receives focus.

<a class="visually-hidden-focusable" href="#content">
  Skip to content
</a>

Therefore, the choice depends on whether the hidden content needs to become visible during keyboard interaction.

6. Use with Buttons

Visually hidden helpers are particularly useful when buttons are represented by visual symbols or other non-text elements.

For example:

<button type="button" class="btn btn-primary">
  <span class="visually-hidden">Open navigation menu</span>
</button>

The visible design can be created separately, while the hidden text provides a meaningful description for assistive technologies.

The important point is that visually hidden text should provide useful semantic information rather than simply duplicating unnecessary content.

7. Use with Images and Decorative Elements

When an image or visual element already has an appropriate alt attribute, adding unnecessary visually hidden text may not be required.

For example:

<img src="logo.png" alt="Company logo">

The alt attribute already provides an accessible description.

However, visually hidden helpers can be useful when additional contextual information is required elsewhere in the interface.

8. Skip Navigation Links

One of the most practical applications of .visually-hidden-focusable is creating a skip-navigation link.

Consider a website with a large navigation menu. A keyboard user may have to move through many navigation links before reaching the main content.

A skip link can solve this problem:

<a class="visually-hidden-focusable" href="#main-content">
  Skip to main content
</a>

<nav>
  <!-- Navigation links -->
</nav>

<main id="main-content">
  <!-- Main page content -->
</main>

The link is not normally displayed, but keyboard users can focus on it and activate it to jump directly to the main content.

9. Difference from display: none

It is important not to confuse visually hidden content with completely hidden content.

For example:

display: none;

removes the element from the normal rendered interface and generally makes it unavailable to assistive technologies.

Bootstrap's .visually-hidden utility has a different purpose. It visually removes the content while retaining it for accessibility.

Therefore:

<p class="d-none">
  Hidden content
</p>

and:

<p class="visually-hidden">
  Accessible hidden content
</p>

should not be treated as equivalent.

The first is intended for content that should be hidden from users generally, while the second is intended for content that should remain accessible to assistive technology.

10. Advantages of Visually Hidden Helpers

Bootstrap Visually Hidden Helpers provide several benefits:

  • They improve accessibility for screen reader users.

  • They allow additional semantic information without increasing visual clutter.

  • They can provide accessible names and descriptions for interface controls.

  • They support keyboard-friendly navigation.

  • They are useful for implementing skip links.

  • They reduce the need to create custom CSS for common accessibility requirements.

  • They help developers build interfaces that accommodate different methods of navigation.

11. Important Considerations

Visually hidden content should be used carefully. It should contain meaningful information that actually helps users who depend on assistive technologies.

Developers should not use .visually-hidden as a replacement for proper semantic HTML, meaningful labels, or appropriate alt text.

For example, form controls should normally have proper labels:

<label for="email">Email address</label>
<input type="email" id="email">

Rather than unnecessarily hiding the label:

<label for="email" class="visually-hidden">
  Email address
</label>

The second approach can be useful in specific interface designs, but visible labels are generally preferable when there is enough space and they improve usability for everyone.

12. Summary

Bootstrap Visually Hidden Helpers provide a simple way to make content accessible without displaying it as part of the normal visual interface. The .visually-hidden class is useful when information should remain available to screen readers, while .visually-hidden-focusable is useful for elements such as skip links that should appear when a keyboard user focuses on them.

These utilities are an important part of accessible Bootstrap development because they allow developers to separate visual presentation from accessible information without removing meaningful content from assistive technologies.