This utility makes content accessible to assistive devices without displaying it on the screen.
“There are real world situations where visually hiding content may be appropriate, while to 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 behaviour is intentional, as otherwise sighted keyboard users wouldn’t be able to determine where the focus indicator is.
<div style="min-height: 1.875rem">
<a href="#" class="pc-visually-hidden">Skip to main content</a>
</div>
Code
Demos
Links that open in new windows
In this demo, the link will open in a new window. Screen readers will announce it as “opens in a new window” even though the text content isn’t visible to sighted users.
<a href="https://example.com" target="_blank" rel="noreferrer noopener">
Link to example.com
<pc-icon
library="default"
icon-style="solid"
name="arrow-up-right-from-square"
style="font-size: 0.75rem; vertical-align: 0.25rem"
aria-hidden="true"
></pc-icon>
<span class="pc-visually-hidden">opens in a new window</span>
</a>
Code
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.
<pc-card style="width: 100%; max-width: 360px;">
<header class="pc-visually-hidden">
Personal info
</header>
<pc-input label="Name" style="margin-bottom: var(--pc-spacing-s)"></pc-input>
<pc-input label="Email" type="email"></pc-input>
</pc-card>
Code
Force visually hidden
There are cases where you want to always visually hide certain content, even when it’s focused. For example when hiding a native checkbox to render a custom one:
If you’re using the autoloader or the standard loader, you can ignore this section. If you’re cherry picking, you can use any of the following snippets to import this utility.
In HTMLIn CSS
To import this utility from the CDN with a link tag, copy this snippet and paste it in your HTML: