# Stack

Stacks children vertically with a token gap.

- Family: layout
- Import: `import { Stack } from "@senvenli/react/layout";`
- Page: https://design.senvenli.com/docs/components/stack
- JSON: https://design.senvenli.com/docs/components/stack.json

## Example: Stacked content

One gap between every child, set with `space`.

```tsx
import { Heading, Badge, Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack space="space-150" align="start">
      <Badge tone="success">Paid</Badge>
      <Heading level={3} size="heading-small">Invoice INV-2041</Heading>
      <Text tone="subtle">Sent to Ada Lovelace on March 18, 2026.</Text>
    </Stack>
  );
}
```

## Examples

### Aligned

`align` places the children on the inline axis.

```tsx
import { Button } from "@senvenli/react/action";
import { Heading, Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack space="space-200" align="center">
      <Stack space="space-050" align="center">
        <Heading level={3} size="heading-small">Invite your team</Heading>
        <Text tone="subtle">Projects are easier with everyone in one place.</Text>
      </Stack>
      <Button variant="primary">Invite people</Button>
    </Stack>
  );
}
```

### As a list

`as` keeps the list semantics while the stack sets the rhythm.

```tsx
import { Text } from "@senvenli/react/display";
import { Box, Stack } from "@senvenli/react/layout";

const STEPS = ["Order placed", "Payment received", "Order shipped"];

export default function Example() {
  return (
    <Stack as="ol" space="space-100">
      {STEPS.map((step) => (
        <Box key={step} as="li" padding="space-150" background="surface-sunken" radius="medium">
          <Text>{step}</Text>
        </Box>
      ))}
    </Stack>
  );
}
```

### Horizontal: A row of actions

Short items side by side with one gap.

```tsx
import { Button } from "@senvenli/react/action";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-100">
      <Button variant="primary">Save changes</Button>
      <Button>Preview</Button>
      <Button variant="subtle">Cancel</Button>
    </Stack>
  );
}
```

### Horizontal: Space between

A title at the start and its actions at the end.

```tsx
import { Button } from "@senvenli/react/action";
import { Heading } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-200" justify="between">
      <Heading level={3} size="heading-small">Customers</Heading>
      <Stack direction="horizontal" space="space-100">
        <Button iconBefore="download">Export</Button>
        <Button variant="primary" iconBefore="plus">Add customer</Button>
      </Stack>
    </Stack>
  );
}
```

### Horizontal: Wrapping

Items move to a new line when the row runs out of room.

```tsx
import { Badge } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

const STATUSES = [
  { label: "Draft", tone: "neutral" },
  { label: "In progress", tone: "information" },
  { label: "Under review", tone: "warning" },
  { label: "Completed", tone: "success" },
  { label: "Canceled", tone: "danger" },
] as const;

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-100">
      {STATUSES.map((status) => (
        <Badge key={status.label} tone={status.tone}>{status.label}</Badge>
      ))}
    </Stack>
  );
}
```

## Guidelines

### When to use it

- Laying out content top to bottom with even spacing.
- Placing buttons, tags or short items in a row.

### Use something else when

- [grid](https://design.senvenli.com/docs/components/grid.md): Children form equal columns.
- [split](https://design.senvenli.com/docs/components/split.md): Panes side by side should stack below a width.

### Do and avoid

- Space with `space` (gap), never margins on the children.

## Accessibility

Built in:

- Layout only; no role.
- Follows the reading direction, so it flips in right-to-left languages.

## API reference

### Stack

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| padding | `Space` |  | no |  |
| paddingInline | `Space` |  | no |  |
| paddingBlock | `Space` |  | no |  |
| background | `Background` |  | no |  |
| radius | `Radius` |  | no |  |
| shadow | `Shadow` |  | no |  |
| border | `Border` |  | no |  |
| as | `LayoutElement` |  | no |  |
| direction | `"vertical" \| "horizontal"` |  | no | `vertical` (default): children stacked on the block axis. |
| space | `Space` |  | no | Gap between children (`gap`, never margins). |
| align | `"start" \| "end" \| "center" \| "stretch" \| Align` |  | no | Cross-axis alignment (inline axis). |
| justify | `Justify` |  | no | Distribution along the inline axis; `start` is the reading start, so RTL flips with it. |
| wrap | `boolean` |  | no | Wrap onto new lines when space runs out. Default `true`. |

Also takes 375 standard DOM and ARIA attributes (id, aria-label, event handlers…).

### Tokens it reads

`--ds-background-brand-subtle`, `--ds-background-danger`, `--ds-background-information`, `--ds-background-neutral`, `--ds-background-selected`, `--ds-background-success`, `--ds-background-warning`, `--ds-border`, `--ds-border-bold`, `--ds-radius-full`, `--ds-radius-large`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-shadow-overflow`, `--ds-shadow-overlay`, `--ds-shadow-raised`, `--ds-space-0`, `--ds-space-025`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-1000`, `--ds-space-150`, `--ds-space-200`, `--ds-space-250`, `--ds-space-300`, `--ds-space-400`, `--ds-space-500`, `--ds-space-600`, `--ds-space-800`, `--ds-surface`, `--ds-surface-overlay`, `--ds-surface-raised`, `--ds-surface-sunken`

## Related

- [grid](https://design.senvenli.com/docs/components/grid.md)
- [box](https://design.senvenli.com/docs/components/box.md)
