Controls and surfaces
visually-hidden
Keeps its content out of sight and still read by screen readers.
When to use it
Words that sighted people get from the layout and others need said: a heading for a region, the unit after a figure, the table behind a chart. Use asChild to hide an element of your own. On a single element the sr-only utility does the same; never use it to hide content from everyone, which is hidden.
See it working
The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Primitives page.
Alert dialog
The project is kept.
Collapsible
The options are closed.
Hover card
The first published program was written by Ada Lovelace.
Menubar
Command: none yet. Ruler: hidden. Zoom: 100.
Navigation menu
Toolbar
Styles: none. Saved 0 times.
One-time code
Typed: nothing yet. Sent: nothing yet.
Password
Words for screen readers
Rosalind Franklin
Add it
npx shadcn@latest add @rivier-ui/visually-hiddenThe registry is named once in components.json: see Installation.
Example
Import it from @/components/ui/visually-hidden.
<VisuallyHidden>Opens in a new tab</VisuallyHidden>
<VisuallyHidden asChild><h2>Search results</h2></VisuallyHidden>What it needs
Plain markup: it can stay a server component. Packages: radix-ui.
Source
The whole file. Once copied it is yours: the registry item holds the same text.
/**
* @name visually-hidden
* @category ui
* @description Keeps its content out of sight and still read by screen readers.
* @when Words that sighted people get from the layout and others need said: a heading for a region, the unit after a figure, the table behind a chart. Use asChild to hide an element of your own. On a single element the `sr-only` utility does the same; never use it to hide content from everyone, which is `hidden`.
* @example
* <VisuallyHidden>Opens in a new tab</VisuallyHidden>
* <VisuallyHidden asChild><h2>Search results</h2></VisuallyHidden>
*/
import { VisuallyHidden as VisuallyHiddenPrimitive } from "radix-ui";
import type { ComponentProps } from "react";
export function VisuallyHidden(props: ComponentProps<typeof VisuallyHiddenPrimitive.Root>) {
return <VisuallyHiddenPrimitive.Root data-slot="visually-hidden" {...props} />;
}