When to use it#
- Use it for context that sighted users get from the layout: which item a button belongs to, what a number counts, or a heading that names a block.
- Use it in lists, tables and cards, where the same short label repeats and each one needs its own name.
- Not for instructions or facts that sighted users need too: write them on the page for everyone.
- Not for a link that skips past the header: use a SkipLink. Never put a link or a control inside VisuallyHidden, because someone using a keyboard would land on something they can’t see.
Example#
Messages 3 unread
A screen reader also reads the hidden text. Nobody sees it.
import { Badge, VisuallyHidden } from '@kvirn-ui/react'
import { useVisuallyHiddenTexts } from './texts.ts'
export function DefaultVisuallyHidden() {
const { texts } = useVisuallyHiddenTexts()
return (
<div>
<p>
{texts.messages} <Badge variant="primary">{texts.messageCount}</Badge>
<VisuallyHidden>{texts.unreadHidden}</VisuallyHidden>
</p>
<p>
<small>{texts.hint}</small>
</p>
</div>
)
}Use cases#
The same button on every row
A list has a “Remove” button on each item. Sighted users see which item a button belongs to by its place. Add the item’s name as hidden text, so each button has its own name and shows up in a list of buttons. The visible word stays first in the name.
- Saved search: housing allowance
- Address: Storgatan 1
import { Button, VisuallyHidden } from '@kvirn-ui/react'
import { useVisuallyHiddenTexts } from './texts.ts'
export function ButtonContext() {
const { texts } = useVisuallyHiddenTexts()
return (
<ul>
<li>
{texts.savedSearch}{' '}
<Button>
{texts.remove}
<VisuallyHidden>{texts.removeSavedSearch}</VisuallyHidden>
</Button>
</li>
<li>
{texts.address}{' '}
<Button>
{texts.remove}
<VisuallyHidden>{texts.removeAddress}</VisuallyHidden>
</Button>
</li>
</ul>
)
}Warning: Don't forget
Keep the visible label at the start of the name, so people who use voice control can say what they see (2.5.3 Label in Name). See What you need to do.
A heading nobody sees
A block of text has no visible title, but screen reader users move from heading to heading. Render the hidden text as the heading level that fits the page.
Contact the library
Phone 0123-45 67 89, weekdays 9 to 16
import { VisuallyHidden } from '@kvirn-ui/react'
import { useVisuallyHiddenTexts } from './texts.ts'
export function HiddenHeading() {
const { texts } = useVisuallyHiddenTexts()
return (
<div>
<VisuallyHidden as="h4">{texts.contactHeading}</VisuallyHidden>
<p>{texts.contactText}</p>
</div>
)
}Props in this example:
ason VisuallyHidden
Information: Did you know?
A hidden heading is in the heading list like any other. Pick the level that keeps the outline in order.
A status shown by an icon
An icon says “approved” to sighted users. Put the same word in hidden text next to it, so it is not lost. Keep the icon itself decorative.
Approved: Application 4821
import { Icon, VisuallyHidden } from '@kvirn-ui/react'
import { useVisuallyHiddenTexts } from './texts.ts'
export function IconStatus() {
const { texts } = useVisuallyHiddenTexts()
return (
<p>
<Icon name="check" /> <VisuallyHidden>{texts.approvedHidden}</VisuallyHidden>
{texts.application}
</p>
)
}Information: Did you know?
An Icon with a label is read as an image with that name. Hidden text is read as part of the sentence around it.
A table column with only buttons
A column of buttons needs no title for sighted users, but its header cell can’t stay empty. Put hidden text in it, so a screen reader user knows what the column holds.
| Decision | Decided on | Actions |
|---|---|---|
| Parking permit 2026-0412 | 3 March 2026 | |
| Building permit 2026-0198 | 21 January 2026 |
import { Button, VisuallyHidden } from '@kvirn-ui/react'
import { useVisuallyHiddenTexts } from './texts.ts'
export function ActionsColumn() {
const { texts } = useVisuallyHiddenTexts()
return (
<table className="kv-table">
<thead>
<tr>
<th scope="col">{texts.decisionHeader}</th>
<th scope="col">{texts.dateHeader}</th>
{/* The column holds only buttons, so it has no visible title. The header cell still
needs text: without it a screen reader user has no name for the column. */}
<th scope="col">
<VisuallyHidden>{texts.actionsHeader}</VisuallyHidden>
</th>
</tr>
</thead>
<tbody>
{texts.decisions.map((decision) => (
<tr key={decision.id}>
<th scope="row">{decision.title}</th>
<td>{decision.date}</td>
<td>
<Button>
{texts.download}
<VisuallyHidden> {decision.title}</VisuallyHidden>
</Button>
</td>
</tr>
))}
</tbody>
</table>
)
}Information: Did you know?
The Table does the same for its details column: the header holds the word “Details”, visually hidden.
A heading that also names a navigation
A footer holds a few links and needs no visible title. Give the hidden heading an id and point the navigation’s aria-labelledby at it. The heading is in the outline, and the same words name the navigation in the list of landmarks a screen reader user can jump through.
import { Link, VisuallyHidden } from '@kvirn-ui/react'
import { useId } from 'react'
import { useVisuallyHiddenTexts } from './texts.ts'
export function LandmarkName() {
const { texts } = useVisuallyHiddenTexts()
const headingId = useId()
return (
// The heading is in the page's outline, and aria-labelledby makes the same words the name of
// the navigation. One hidden text does both, and they can't drift apart.
<nav aria-labelledby={headingId}>
<VisuallyHidden as="h4" id={headingId}>
{texts.footerHeading}
</VisuallyHidden>
<ul>
<li>
<Link.Root href="#accessibility-statement">{texts.accessibilityStatement}</Link.Root>
</li>
<li>
<Link.Root href="#privacy">{texts.privacy}</Link.Root>
</li>
</ul>
</nav>
)
}Props in this example:
ason VisuallyHidden
Accessibility#
What it does for you#
- APG pattern: none. WCAG technique C7 (hide text visually and keep it for assistive technology).
- Deviations: none
- Native elements used:
<span>. The consumer can pick another withas(allowed elements below), and its own semantics apply.
VisuallyHidden is a span with a class, so the theme can clip it. It adds no role, ARIA, text or behaviour: its content stays in the accessibility tree and is read in the flow of the sentence.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| VisuallyHidden | <span> → no role | none | class="kv-visually-hidden". Attributes (id, aria-*) and the ref reach the element unchanged. The text is yours |
| VisuallyHidden | as | the chosen element's own | One element, chosen with a string. as="h2" gives a heading nobody sees. A value outside the list is a type error and, in JavaScript, warns once in development and renders the default element. |
It announces nothing.
What you need to do#
- Write the text in the page's language, or put it in a nested
KvirnProviderwithuseLocale().localePropson your own element (3.1.2 Language of Parts (AA)). - Don't hide what everyone needs. Text that only a screen reader gets is for context (a count, a status word, a name), not for instructions sighted users also need (3.3.2 Labels or Instructions (A): instructions go to all users, not only to those using assistive technology).
- When hidden text is part of a control's name, start the name with the visible label (2.5.3 Label in Name (A)), so people who use voice control can say what they see.
Information: Did you know?
Keep the hidden text short. W3C’s technique C7 notes that hidden text can make a page “overly chatty” for screen reader users.
Visual and modes#
Headless: no CSS. With the default theme, the text is clipped to a tiny box and kept in the page, on one line. It is never display: none or visibility: hidden, which would remove it from the accessibility tree. The rule has no weight, so your own CSS wins. Forced colours, contrast, target size and motion: not applicable.
Focus management#
- Initial focus: not moved. Trap: no. Restore to: not applicable.
- Never put a focusable element inside it: a control that takes focus and can't be seen fails 2.4.7 Focus Visible (AA). The bypass link is its own part, SkipLink.
Warning: Don't forget
Never put a link, button or field inside VisuallyHidden. Someone using a keyboard would land on it and see nothing (2.4.7 Focus Visible).
Allowed elements#
A tag outside the list changes the page's outline or meaning (1.3.1 Info and Relationships (A), 4.1.2 Name, Role, Value (A)). as is a string, so it works from a Server Component.
| Part | `as` | Why |
|---|---|---|
| VisuallyHidden | span (default), div, p, h2 to h6 | A hidden heading names a region in the outline; div and p hold block text. No h1 (the page's title is visible), no landmark or interactive element |
WCAG success criteria#
- 1.3.1 Info and Relationships (A): context that sighted users get from the layout is also there for assistive technology, because the text stays in the accessibility tree (
visually-hidden.test.tsx: its text stays in the accessibility tree). - 4.1.2 Name, Role, Value (A): hidden text inside a control becomes part of the control's name (
visually-hidden.test.tsx › hidden text inside a control becomes part of the control’s name).
Keyboard#
VisuallyHidden has no keys of its own. What you put in it keeps its own keys.
API reference#
import { VisuallyHidden, useVisuallyHidden } from '@kvirn-ui/react'VisuallyHidden
Renders <span> with no role. It takes every attribute of the element and passes ref to it. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
'span' | 'div' | 'p' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'span' | Changes the element, for example as="h2" for a hidden heading. The element’s own meaning applies. There is no h1: the page’s title is visible. In JavaScript, an element outside the list is replaced by a span and warns once in development. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-visually-hidden | always | The part class. The default theme clips the element to a tiny box and keeps it in the page. Your className joins it. |
useVisuallyHidden
Use it on an element of your own. It takes no options, and it adds no role, ARIA or tabindex.
Result
| Prop | Type | Default | Description |
|---|---|---|---|
VisuallyHiddenPartProps | – | Spread on your element: only the className "kv-visually-hidden". Join a class of your own with mergeProps. |
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | visually-hidden.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | visually-hidden.test.tsx › hidden text inside a control becomes part of the control’s name; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | visually-hidden.test.tsx › is not a Tab stop and adds only its class |
| Focus order and management | n/a | n/a | n/a | nothing focusable: the component never takes or moves focus |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | n/a | n/a | n/a | renders no visible part: its content is clipped away by design |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |