> For AI agents: the complete documentation index is available at https://rickyshin93.github.io/tao-ui/llms.txt, the full documentation bundle is available at https://rickyshin93.github.io/tao-ui/llms-full.txt.

# Stack

Layout`@rockshin/tao-ui`

[Examples](#examples)[API](#api)

Composes children in a flex row or column with consistent spacing.

## When to use

Use Stack for simple one-dimensional layout and spacing.

**Recommended**

- Prefer Stack over one-off margin rules for repeated spacing.
- Use semantic containers when the layout has richer meaning.
- Pass breakpoint maps (for example, `direction={{ xs: 'vertical', md: 'horizontal' }}`) for responsive layouts.

**Avoid**

- Do not use the component outside its intended interaction model.

## Examples


### Basic usage
```tsx preview
import { Stack, Tag } from '@rockshin/tao-ui';

function StackExample() {
  return (
    <Stack direction="horizontal" gap="md" align="center">
      <Tag>Design</Tag>
      <Tag>Engineering</Tag>
      <Tag>Research</Tag>
    </Stack>
  );
}

export default StackExample;
```

### Direction, spacing, and alignment
```tsx preview
import { Stack, Tag } from '@rockshin/tao-ui';

function StackVariants() {
  return (
    <Stack gap="lg">
      <Stack direction="horizontal" gap="sm" align="center">
        <Tag>Small gap</Tag>
        <Tag>Centered</Tag>
      </Stack>
      <Stack direction="horizontal" gap="lg" align="end">
        <Tag>Large gap</Tag>
        <Tag>End aligned</Tag>
      </Stack>
    </Stack>
  );
}

export default StackVariants;
```

### Responsive direction
```tsx preview
import { Button, Stack } from '@rockshin/tao-ui';

function ResponsiveStack() {
  return (
    <Stack
      direction={{ xs: 'vertical', md: 'horizontal' }}
      gap={{ xs: 'sm', md: 'lg' }}
    >
      <Button>Save</Button>
      <Button variant="secondary">Preview</Button>
      <Button variant="ghost">Cancel</Button>
    </Stack>
  );
}

export default ResponsiveStack;
```

### Alignment
Use align and justifyContent on the root to position children.
```tsx preview
import { Stack, Button } from '@rockshin/tao-ui';
export default function Example() {
  return (
    <Stack
      align="center"
      styles={{
        root: {
          justifyContent: 'space-between',
          minHeight: 100,
          width: '100%',
        },
      }}
    >
      <Button>Start</Button>
      <span>Centered vertically</span>
      <Button>End</Button>
    </Stack>
  );
}
```

### Wrapping items
Enable flexWrap on the semantic root so a long toolbar can wrap.
```tsx preview
import { Stack, Button } from '@rockshin/tao-ui';
export default function Example() {
  return (
    <Stack styles={{ root: { flexWrap: 'wrap' } }}>
      {['Overview', 'Members', 'Permissions', 'Billing', 'Settings'].map(
        (item) => (
          <Button key={item}>{item}</Button>
        ),
      )}
    </Stack>
  );
}
```

### Responsive direction and gap
Use a vertical arrangement in narrow viewports and horizontal at wider breakpoints. Compare the phone preview.
```tsx preview="iframe-follow"
import { Stack, Input, Button } from '@rockshin/tao-ui';
export default function Example() {
  return (
    <Stack
      direction={{ xs: 'vertical', md: 'horizontal' }}
      gap={{ xs: 'sm', md: 'lg' }}
      align="stretch"
    >
      <Input aria-label="Email address" placeholder="name@example.com" />
      <Button variant="primary">Continue</Button>
    </Stack>
  );
}
```

### Nested layouts
Let the outer stack space sections and the inner stack group related actions.
```tsx preview
import { Stack, Button } from '@rockshin/tao-ui';
export default function Example() {
  return (
    <Stack direction="vertical" gap="lg">
      <div>
        <strong>Workspace</strong>
        <p>Invite members and manage access.</p>
      </div>
      <Stack styles={{ root: { flexWrap: 'wrap' } }}>
        <Button variant="primary">Invite member</Button>
        <Button>Manage roles</Button>
      </Stack>
    </Stack>
  );
}
```

## API


### [#](#stack)Stack



| Property | Description | Type | Default Value |
| --- | --- | --- | --- |
| direction | Flex direction. Accepts a breakpoint map, e.g.
`direction={{ xs: 'vertical', md: 'horizontal' }}` — the largest matching
breakpoint wins (SSR/first render falls back to the plain default). | `TaoResponsiveValue<StackDirection> | undefined` | `vertical` |
| className | Additional css class | `string | undefined` | `-` |
| style | Additional style | `CSSProperties | undefined` | `-` |

