---
title: "Visually Hidden · Ark UI — StyleX Blocks"
description: "Hides text visually while keeping it accessible to assistive technology, with an optional focusable mode."
url: "https://stylexblocks.com/components/ark-ui/visually-hidden/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Visually Hidden

Hides text visually while keeping it accessible to assistive technology, with an optional focusable mode.

- Behavior engine: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/visually-hidden.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/visually-hidden.md)
- Category: Layout
- HTML page: https://stylexblocks.com/components/ark-ui/visually-hidden/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init
```

Then add the item as source you own:

```sh
npx stylexblocks add visually-hidden
```

Equivalent: `npx shadcn add @stylexblocks/visually-hidden`. Registry item JSON: https://stylexblocks.com/r/ark-ui/visually-hidden.json

## Usage

```tsx
import { VisuallyHidden } from "#components/ui/ark-ui/visually-hidden.tsx";

export function Example() {
  return (
    <button type="button">
      <svg aria-hidden="true" width="16" height="16" viewBox="0 0 16 16" />
      <VisuallyHidden>Close dialog</VisuallyHidden>
    </button>
  );
}
```

## Source

`components/ui/ark-ui/visually-hidden.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/ark-ui/create-component.tsx";
import { defineRecipe } from "#lib/recipe-props.ts";

const visuallyHiddenStyles = stylex.create({
  base: {
    position: "absolute",
    width: "1px",
    height: "1px",
    paddingTop: 0,
    paddingRight: 0,
    paddingBottom: 0,
    paddingLeft: 0,
    marginTop: "-1px",
    marginRight: "-1px",
    marginBottom: "-1px",
    marginLeft: "-1px",
    overflow: "hidden",
    clipPath: "inset(50%)",
    whiteSpace: "nowrap",
    borderWidth: 0,
    borderStyle: "none",
  },
});

const visuallyHiddenFocusable = stylex.create({
  false: {},
  true: {
    position: {
      default: "absolute",
      ":is(:focus, :focus-visible)": "static",
    },
    width: {
      default: "1px",
      ":is(:focus, :focus-visible)": "auto",
    },
    height: {
      default: "1px",
      ":is(:focus, :focus-visible)": "auto",
    },
    marginTop: {
      default: "-1px",
      ":is(:focus, :focus-visible)": 0,
    },
    marginRight: {
      default: "-1px",
      ":is(:focus, :focus-visible)": 0,
    },
    marginBottom: {
      default: "-1px",
      ":is(:focus, :focus-visible)": 0,
    },
    marginLeft: {
      default: "-1px",
      ":is(:focus, :focus-visible)": 0,
    },
    overflow: {
      default: "hidden",
      ":is(:focus, :focus-visible)": "visible",
    },
    clipPath: {
      default: "inset(50%)",
      ":is(:focus, :focus-visible)": "none",
    },
    whiteSpace: {
      default: "nowrap",
      ":is(:focus, :focus-visible)": "normal",
    },
  },
});

const visuallyHiddenRecipe = defineRecipe({
  styles: visuallyHiddenStyles,
  axes: { focusable: visuallyHiddenFocusable },
  defaultVariants: { focusable: "false" },
});

/**
 * VisuallyHidden — hides content visually while keeping it accessible to
 * screen readers. Set `focusable="true"` to reveal on keyboard focus.
 * Composition via `asChild`.
 */
export const VisuallyHidden = createComponent(
  "span",
  visuallyHiddenRecipe,
  "VisuallyHidden",
);
export type VisuallyHiddenProps = React.ComponentProps<typeof VisuallyHidden>;
```
