# Visually Hidden

Content hidden visually while remaining available to assistive technology.

Content hidden visually while remaining available to assistive technology.

```tsx
import { Button, VisuallyHidden } from "@zentara-co/zenos-ui";

function VisuallyHiddenExample() {
  return (
    <Button variant="primary">
      Notifications
      <VisuallyHidden> (3 unread)</VisuallyHidden>
    </Button>
  );
}
```

## Import

```tsx
import { VisuallyHidden } from "@zentara-co/zenos-ui";
```

## Icon-only controls

Place a concise hidden label inside an icon-only button when visible text would be redundant. The button remains the interactive element; VisuallyHidden only contributes text to its accessible name.

```tsx
import { CopyIcon, DotsThreeVerticalIcon } from "@phosphor-icons/react";
import { Button, Stack, VisuallyHidden } from "@zentara-co/zenos-ui";

function VisuallyHiddenIconExample() {
  return (
    <Stack direction="row" gap="3">
      <Button variant="primary">
        <CopyIcon />
        <VisuallyHidden>Copy project identifier</VisuallyHidden>
      </Button>
      <Button variant="primary">
        <DotsThreeVerticalIcon />
        <VisuallyHidden>Open project actions</VisuallyHidden>
      </Button>
    </Stack>
  );
}
```

## Supplemental context

Hidden text can clarify a visible count, symbol, or abbreviated status. Keep the primary information visible so all users receive the same result.

```tsx
import { Badge, Button, Stack, Text, VisuallyHidden } from "@zentara-co/zenos-ui";

function VisuallyHiddenContextExample() {
  return (
    <Stack gap="4" className="w-full max-w-md">
      <Button variant="primary">
        Notifications
        <Badge variant="default" color="information">
          3
        </Badge>
        <VisuallyHidden> unread</VisuallyHidden>
      </Button>
      <Stack direction="row" gap="2" align="center">
        <span
          aria-hidden="true"
          className="size-2 rounded-full bg-background-success-bold-default"
        />
        <Text>API gateway</Text>
        <VisuallyHidden> status:</VisuallyHidden>
        <Text color="success">Healthy</Text>
      </Stack>
    </Stack>
  );
}
```

## Referenced labels

Use an `id` with `aria-labelledby` when a control needs a persistent accessible name but the surrounding visual design cannot show one. A placeholder is not a label.

```tsx
import { Input, Stack, Text, VisuallyHidden } from "@zentara-co/zenos-ui";

function VisuallyHiddenLabelExample() {
  return (
    <Stack gap="4" className="w-full max-w-md">
      <VisuallyHidden id="audit-search-label">Search audit events</VisuallyHidden>
      <Input aria-labelledby="audit-search-label" placeholder="Search" type="search" />
      <Text size="s" color="subtle">
        The visible placeholder is a hint; the hidden text supplies the persistent accessible name.
      </Text>
    </Stack>
  );
}
```

## Live status

VisuallyHidden can carry a concise live-region announcement when the same outcome is also visible. Avoid announcing every intermediate update or duplicating text that another live region already reports.

```tsx
import { Button, Stack, Text, VisuallyHidden } from "@zentara-co/zenos-ui";
import { useState } from "react";

function VisuallyHiddenLiveExample() {
  const [count, setCount] = useState(0);

  return (
    <Stack gap="3" align="start">
      <Button variant="primary" onClick={() => setCount((current) => current + 1)}>
        Add result
      </Button>
      <Text>Visible results: {count}</Text>
      <VisuallyHidden aria-live="polite">
        {count === 0 ? "No results added" : `${count} result${count === 1 ? "" : "s"} available`}
      </VisuallyHidden>
    </Stack>
  );
}
```

## When not to use it

Do not hide essential instructions, error recovery, or content useful to sighted users. VisuallyHidden always renders a clipped `span`; it is not suitable for skip links or any focusable control that must become visible on focus. Style the focusable element itself with a visually-hidden-until-focused pattern instead.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| children | ReactNode | — | Content exposed to assistive technology. |
| id | string | — | Allows another element to reference the hidden text as a label or description. |
| aria-live | off \| polite \| assertive | — | Optionally announces changing hidden status text. |
| native props | React.ComponentPropsWithoutRef<'span'> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

The content remains in the accessibility tree and normal DOM while occupying one clipped pixel visually. Test its result through the final accessible name or description rather than checking only that hidden text exists. Avoid repeating visible labels verbatim, and keep hidden copy synchronized when visible state changes.

Source: https://zenos-ui.pages.dev/components/visually-hidden/