Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / More

VisuallyHidden

Content for screen readers only: out of sight, still in the accessibility tree and read in place. With focusable, it is shown while something inside it has keyboard focus.

Hidden but still read

When to useLink to "When to use"

  • Extra words for screen readers: "items in the basket" after a bare number, or the rest of a short "Read more" link.
  • A heading only screen readers need: a section whose purpose is clear from its layout still gets a heading in the page outline.
  • Keyboard-only links: with focusable, a link that appears when it is tabbed to.

Use something else when:

  • the control has only an icon: IconButton takes a label and shows it as a tooltip
  • it is the page's "Skip to content" link: SkipLink
  • it announces a change: Announcer's live region

UsageLink to "Usage"

tsx
Copy
import { VisuallyHidden } from "@arshad-shah/cynosure";

<p>Total: 42 <VisuallyHidden>items in the basket</VisuallyHidden></p>

<VisuallyHidden as="h2" id="plans">Plans and pricing</VisuallyHidden>

<VisuallyHidden focusable as="div">
  <Link href="#comments">Jump to the comments</Link>
</VisuallyHidden>

A name for a controlLink to "A name for a control"

The hidden text becomes the accessible name of the button around it.

Names an icon only control

A heading for screen readersLink to "A heading for screen readers"

as sets the element, so a hidden heading takes its place in the outline and can name a section through its id.

Heading for screen readers

Shown on focusLink to "Shown on focus"

With focusable, the content joins the normal flow while something inside it has focus and hides again when focus leaves. Press Tab in the example.

Focusable shows on focus

PropsLink to "Props"

Every prop of VisuallyHidden
PropWhat it doesTypeDefault
childrenRequired
The text for screen readers.ReactNode
as
The element rendered. Use span inside a line of text, div or p for a block, and a heading level to give a section a heading that only screen readers announce. Default "span"."div" | "span" | "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6""span"
focusable
Show the content while something inside it has focus, for links and buttons that only keyboard users need. It is hidden again when focus leaves. Default false.booleanfalse
id
Set on the element, for aria-labelledby, aria-describedby and in-page links.string
className
Added to the element, for the layout of a focusable one while it is shown.string

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

Behaviour and accessibility, table 1
InputResult
Tab to a link inside a focusable oneThe content is shown in place
Tab awayHidden again
  • Hidden, not removed: one clipped pixel, out of the flow. Never display: none, visibility: hidden or aria-hidden, so it is read and can name a control.
  • One rule: it uses the shared .cy-visually-hidden rule in base.css, which every Cynosure component that hides text also uses.
  • Focusable content: without focusable, a link inside stays invisible when focused. Always set focusable for content a keyboard can reach.

TouchLink to "Touch"

Nothing to press of its own. A focusable one keeps the hit areas of the links and buttons it holds.

ThemingLink to "Theming"

No tokens: hiding has no look. While shown, a focusable one has no styles of its own; use className for its layout.

SkipLink · IconButton · Announcer · Link

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog