# Stack

Arrange siblings along one responsive axis with typed spacing, alignment, and sizing.

`Stack` arranges siblings in a row or column. Its direction, spacing, alignment, distribution, wrapping, and padding can adapt at Zenos breakpoints.

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

function StackExample() {
  return (
    <Stack
      as="ul"
      direction={{ base: "column", md: "row" }}
      gap={{ base: "3", md: "4" }}
      align={{ base: "stretch", md: "center" }}
      className="w-full list-none rounded-xl border border-border bg-background-neutral-card p-4"
    >
      <StackItem as="li" grow>
        <Stack gap="1">
          <Text weight="bold">Production workspace</Text>
          <Text size="s" color="subtle">
            12 services monitored
          </Text>
        </Stack>
      </StackItem>
      <StackItem as="li">
        <Cluster gap="2">
          <Button size="sm" variant="primary">
            Settings
          </Button>
          <Button size="sm">Open workspace</Button>
        </Cluster>
      </StackItem>
    </Stack>
  );
}
```

## Import

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

## Responsive direction

Stack uses `column` by default. Its direction accepts only `row` and `column`, either directly or through a responsive object.

```tsx
<Stack direction={{ base: "column", md: "row" }} gap="4">
  ...
</Stack>
```

Use HStack or VStack when the direction is fixed and logical-axis alignment reads more clearly.

## Wrapping and spacing

`gap`, `align`, `justify`, `wrap`, and every padding prop accept responsive values. Wrap accepts booleans as shorthand, plus `nowrap`, `wrap`, and `wrap-reverse`.

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

function StackWrapExample() {
  return (
    <Stack
      direction="row"
      wrap={{ base: true, lg: false }}
      gap={{ base: "2", md: "3" }}
      padding={{ base: "3", md: "5" }}
      className="w-full rounded-xl border border-border bg-background-neutral-card"
    >
      {["Authentication", "Infrastructure", "Data protection", "Observability"].map((item) => (
        <Badge key={item} variant="soft" color="gray">
          {item}
        </Badge>
      ))}
    </Stack>
  );
}
```

Logical padding props such as `paddingInlineStart` and `paddingBlockEnd` adapt to writing direction. More specific padding classes can override general padding at the same breakpoint.

## Sizing and scrolling

Stack supports tokenized width, height, minimum, and maximum constraints. `isScrollable` adds overflow scrolling and is most useful with a constrained height or width.

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

function StackSizingExample() {
  return (
    <Stack
      gap="3"
      width="full"
      maxWidth="lg"
      height="xs"
      isScrollable
      padding="3"
      className="rounded-xl border border-border bg-background-neutral-card"
    >
      {Array.from({ length: 8 }, (_, index) => (
        <Box key={index} className="shrink-0 rounded-lg border border-border p-3">
          <Text size="s">Activity item {index + 1}</Text>
        </Box>
      ))}
    </Stack>
  );
}
```

## Semantics

Use `as="ul"` with list-item children for ordered collections, `as="nav"` for navigation, or another element that matches the content. Native props and refs follow the selected element.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| as | ElementType | div | Rendered semantic element. |
| direction | Responsive<row \| column> | column | Responsive main axis. |
| align / justify | Responsive<Align \| Justify> | — | Cross-axis alignment and main-axis distribution. |
| gap | Responsive<Spacing> | 4 | Space between children. |
| wrap | Responsive<boolean \| nowrap \| wrap \| wrap-reverse> | false | Responsive flex wrapping. |
| padding / paddingX / paddingY / logical padding props | Responsive<Spacing> | — | Physical and logical responsive padding. |
| width / height / minWidth / maxWidth / minHeight / maxHeight | SizeToken | — | Structural size constraints. |
| isScrollable | boolean | false | Enables overflow scrolling within a constrained Stack. |
| native props | React.HTMLAttributes<HTMLElement> | — | 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

Responsive direction changes presentation without changing source order. Keep DOM order meaningful for reading and keyboard navigation. Independently scrollable stacks need a visible size constraint and must remain usable at 200% zoom.

Source: https://zenos-ui.pages.dev/layout/stack/