---
title: "Visually Hidden · UI SDK — StyleX Blocks"
description: "Hides text visually while keeping it accessible to assistive technology, with an optional focusable mode."
url: "https://stylexblocks.com/components/ui-sdk/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: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/visually-hidden.md), [Base UI](https://stylexblocks.com/components/base-ui/visually-hidden.md)
- Category: Layout
- Used in blocks: [AI Chat Conversation](https://stylexblocks.com/block/ui-sdk/ai-chat.md), [AI Chat Landing](https://stylexblocks.com/block/ui-sdk/ai-chat-landing.md), [Analytics Dashboard](https://stylexblocks.com/block/ui-sdk/analytics-dashboard.md), [Canvas Editor](https://stylexblocks.com/block/ui-sdk/canvas-editor.md), [Collapsible Table](https://stylexblocks.com/block/ui-sdk/collapsible-table.md), [Inline Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-inline.md), [Grouped Table](https://stylexblocks.com/block/ui-sdk/grouped-table.md), [Messaging Shell](https://stylexblocks.com/block/ui-sdk/messaging-shell.md), [Searchable Table](https://stylexblocks.com/block/ui-sdk/searchable-table.md), [Simple Table](https://stylexblocks.com/block/ui-sdk/simple-table.md), [Tree Table](https://stylexblocks.com/block/ui-sdk/tree-table.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/visually-hidden/

## Install

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

```sh
npx stylexblocks init --style ui-sdk
```

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/ui-sdk/visually-hidden.json

## Usage

```tsx
import { VisuallyHidden } from "#components/ui/ui-sdk/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/ui-sdk/visually-hidden.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/ui-sdk/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 `render`.
 */
export const VisuallyHidden = createComponent(
  "span",
  visuallyHiddenRecipe,
  "VisuallyHidden",
);
export type VisuallyHiddenProps = React.ComponentProps<typeof VisuallyHidden>;
```
