---
title: "Collapsible · Ark UI — StyleX Blocks"
description: "Show and hide a region of content behind a trigger, with a bare content slot to style freely."
url: "https://stylexblocks.com/components/ark-ui/collapsible/"
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/"
---

# Collapsible

Show and hide a region of content behind a trigger, with a bare content slot to style freely.

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

## 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 collapsible
```

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

## Usage

```tsx
import { Collapsible } from "#components/ui/ark-ui/collapsible.tsx";
import { Button } from "#components/ui/ark-ui/button.tsx";

export function Example() {
  return (
    // the machine wires the trigger and animates the content; the content
    // slot is deliberately bare — style it freely via the style prop
    <Collapsible.Root defaultOpen>
      <Collapsible.Trigger asChild>
        <Button variant="surface">Show advanced options</Button>
      </Collapsible.Trigger>
      <Collapsible.Content>
        Custom domains, edge caching, and preview deployments.
      </Collapsible.Content>
    </Collapsible.Root>
  );
}
```

## Source

`components/ui/ark-ui/collapsible.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { Collapsible as ArkCollapsible } from "@ark-ui/react/collapsible";
import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";
import { defineSlotRecipe } from "#lib/recipe-props.ts";
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'

const collapsibleContent = stylex.create({
  base: {
    overflow: 'hidden',
    animationName: {
      default: null,
      ':is([data-open], [data-state="open"])': 'expand-height, fade-in',
      ':is([data-closed], [data-state="closed"])': 'collapse-height, fade-out',
    },
    animationDuration: {
      default: null,
      ':is([data-open], [data-state="open"])': durations.moderate,
      ':is([data-closed], [data-state="closed"])': durations.moderate,
    },
  },
})

const collapsibleRecipe = defineSlotRecipe({
  slots: {
    content: { styles: collapsibleContent },
  },
  defaultVariants: {},
});

const { withContext } = createSlotRecipeContext(collapsibleRecipe);

/**
 * Collapsible — Ark's collapsible machine wearing the collapsible slot
 * recipe: trigger wiring, height animation hooks, and open state all come
 * from the machine. The content slot carries only the open/close height
 * animation — style the rest freely per use. Every part composes via
 * `asChild`.
 */
export const Collapsible = {
  Root: ArkCollapsible.Root,
  Trigger: ArkCollapsible.Trigger,
  Content: withContext(ArkCollapsible.Content, "content", "CollapsibleContent"),
  Context: ArkCollapsible.Context,
  Indicator: ArkCollapsible.Indicator,
};
```
