Skip to
Keyboard shortcuts

Use the up and down arrow keys to move between items. Press Alt+Shift+K to open this list again.

Alpha version out now. The API may still change.

VisuallyHidden

Text that screen reader users get and nobody sees. It stays in the page, so a screen reader (software that reads the screen aloud) reads it in the flow of the sentence.

Package
@kvirn-ui/react
Testing
Automated. Core 0 of 2, Release 0 of 3

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.

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

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

Props in this example:

  • as on 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

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.

DecisionDecided onActions
Parking permit 2026-04123 March 2026
Building permit 2026-019821 January 2026

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.

Props in this example:

  • as on 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 with as (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.

PartElement / roleARIANotes
VisuallyHidden<span> → no rolenoneclass="kv-visually-hidden". Attributes (id, aria-*) and the ref reach the element unchanged. The text is yours
VisuallyHiddenasthe chosen element's ownOne 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 KvirnProvider with useLocale().localeProps on 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
VisuallyHiddenspan (default), div, p, h2 to h6A 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.

PropTypeDefaultDescription
as'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 attributeValuesMeaning
kv-visually-hiddenalwaysThe 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

PropTypeDefaultDescription
visuallyHiddenPropsVisuallyHiddenPartProps–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 + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apassvisually-hidden.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apassvisually-hidden.test.tsx › hidden text inside a control becomes part of the control’s name; expectNoA11yViolations
Keyboard contract rows (Vitest browser)passn/apassvisually-hidden.test.tsx › is not a Tab stop and adds only its class
Focus order and managementn/an/an/anothing focusable: the component never takes or moves focus
Display modes (forced colours, 320px reflow, text spacing, reduced motion)n/an/an/arenders no visible part: its content is clipped away by design
Core (required for beta)
NVDA + Chrome + Windowspendingpendingpending
VoiceOver + Safari + iOSpendingpendingpending
Release (before 1.0 and each minor)
JAWS + Chrome + Windowspendingpendingpending
TalkBack + Chrome + Androidpendingpendingpending
VoiceOver + Safari + macOSpendingpendingpending