Light Dark System

Visually Hidden

<p-visually-hidden> | PVisuallyHidden
Since 1.0 stable

The visually hidden utility makes content accessible to assistive devices without displaying it on the screen.

According to The A11Y Project, “there are real world situations where visually hiding content may be appropriate, while the content should remain available to assistive technologies, such as screen readers. For instance, hiding a search field’s label as a common magnifying glass icon is used in its stead.”

Since visually hidden content can receive focus when tabbing, the element will become visible when something inside receives focus. This behavior is intentional, as sighted keyboard user won’t be able to determine where the focus indicator is without it.

<div style="min-height: 1.875rem;">
  <p-visually-hidden>
    <a href="#">Skip to main content</a>
  </p-visually-hidden>
</div>

Examples

In this example, the link will open a new window. Screen readers will announce “opens in a new window” even though the text content isn’t visible to sighted users.

<a href="https://example.com/" target="_blank">
  Visit External Page
  <p-icon name="box-arrow-up-right"></p-icon>
  <p-visually-hidden>opens in a new window</p-visually-hidden>
</a>

Content Conveyed By Context

Adding a label may seem redundant at times, but they’re very helpful for unsighted users. Rather than omit them, you can provide context to unsighted users with visually hidden content that will be announced by assistive devices such as screen readers.

Personal Info
<p-card style="width: 100%; max-width: 360px;">
  <header>
    <p-visually-hidden>Personal Info</p-visually-hidden>
  </header>
  <p-input label="Name" style="margin-bottom: .5rem;"></p-input>
  <p-input label="Email" type="email"></p-input>
</p-card>

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

Script Import Bundler React

To import this component from the CDN using a script tag:

<script type="module" src="https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/components/visually-hidden/visually-hidden.js"></script>

To import this component from the CDN using a JavaScript import:

import 'https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/components/visually-hidden/visually-hidden.js';

To import this component using a bundler:

import 'pure-uikit/dist/components/visually-hidden/visually-hidden.js';

To import this component as a React component:

import PVisuallyHidden from 'pure-uikit/dist/react/visually-hidden';

Slots

Name Description
(default) The content to be visually hidden.

Learn more about using slots.