<!-- index: /slotted/llms.txt -->
# stack

`data-ui="stack"` · Column of items with a gap.

## Minimal example

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Heading, Text } from '@slotted/react/typography';

export default function StackBasic() {
  return (
    <Stack>
      <Heading level={2} size="md">
        Order SO-10482
      </Heading>
      <Text tone="muted">Placed by Maria Chen on March 4 for the Harbor Street store.</Text>
      <Inline gap={2}>
        <Badge tone="success">Shipped</Badge>
        <Badge tone="info">Wholesale</Badge>
      </Inline>
      <Text>Estimated delivery on March 9.</Text>
    </Stack>
  );
}
```

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `gap` | `0 \| 1 \| … \| 12` | 6 | Stack | Sets the separation between children as a step on the space scale. |
| `align` | `'start' \| 'center' \| 'end' \| 'stretch'` | — | Stack | Positions children across the column, along the inline axis. Without it, children stretch to the width of the column. |
| `justify` | `'start' \| 'center' \| 'end' \| 'between' \| 'around' \| 'evenly'` | — | Stack | Positions children along the column and distributes the free space. It moves nothing until the stack is taller than its content. |
| `render` | `(props) => ReactNode` | — | Stack | Renders a different root element from the props it receives. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `gap` | `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12` | `6` |
| `align` | `start`, `center`, `end`, `stretch` | — |
| `justify` | `start`, `center`, `end`, `between`, `around`, `evenly` | — |

## Rules

- Stack has no role and no ARIA. It arranges what you write inside it, and the children keep whatever semantics they already had.
- There is no axis that reverses the children. Visual order stays DOM order, which is what WCAG 2.2 SC 1.3.2 asks for (technique C27, failure F1) and what keeps the Tab order matching the page.
- The element is yours to choose. Render a ul when the children are list items and a form when they are fields, so the document says what it means.
- Separation is a step on the space scale, stated in rem, so it grows with the browser zoom WCAG 1.4.4 requires.
- Alignment uses the logical keywords, so a right-to-left document is the same column mirrored.

## Tokens

`--slotted-space-1`, `--slotted-space-10`, `--slotted-space-11`, `--slotted-space-12`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-space-6`, `--slotted-space-7`, `--slotted-space-8`, `--slotted-space-9`

## Examples

### A form as the root element

Excerpt — not a complete module

```tsx
<Stack gap={6} render={(props) => <form {...props} onSubmit={save} />}>
  <Field>
    <FieldLabel>Email</FieldLabel>
    <TextField type="email" />
  </Field>
  <Button type="submit">Sign in</Button>
</Stack>;
```

### The outer stack separates sections, the inner separates lines

Excerpt — not a complete module

```tsx
<Stack gap={8}>
  <Stack gap={2}>
    <Text weight="semibold">Payment method</Text>
    <Text tone="muted">Visa ending 4242</Text>
  </Stack>
  <Stack gap={2}>
    <Text weight="semibold">Billing address</Text>
    <Text tone="muted">200 Harbor Street</Text>
  </Stack>
</Stack>;
```

### Header, body and footer pushed apart

Excerpt — not a complete module

```tsx
<Stack gap={4} justify="between" style={{ blockSize: '100%' }}>
  <Header />
  <Body />
  <Footer />
</Stack>;
```

### align.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Card, CardBody, CardHeader } from '@slotted/react/card';
import { Stack } from '@slotted/react/stack';
import { Heading } from '@slotted/react/typography';

const ALIGNS = ['start', 'center', 'end', 'stretch'] as const;

export default function StackAlign() {
  return (
    <Stack gap={4}>
      {ALIGNS.map((align) => (
        <Card key={align}>
          <CardHeader>
            <Heading level={2} size="sm">
              align {align}
            </Heading>
          </CardHeader>
          <CardBody>
            <Stack align={align} gap={2}>
              <Badge tone="info">Wholesale</Badge>
              <Badge tone="warning">Priority shipping</Badge>
              <Badge tone="secondary">Fragile</Badge>
            </Stack>
          </CardBody>
        </Card>
      ))}
    </Stack>
  );
}
```

### form.tsx

Example

```tsx
import { Button } from '@slotted/react/button';
import { Field, FieldLabel } from '@slotted/react/field';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { TextField } from '@slotted/react/text-field';

export default function StackForm() {
  return (
    <Stack
      gap={5}
      render={(props) => (
        <form
          {...props}
          onSubmit={(event) => {
            event.preventDefault();
          }}
        />
      )}
    >
      <Field required>
        <FieldLabel>Email</FieldLabel>
        <TextField type="email" autoComplete="email" />
      </Field>
      <Field required>
        <FieldLabel>Password</FieldLabel>
        <TextField type="password" autoComplete="current-password" />
      </Field>
      <Inline justify="end">
        <Button type="submit">Sign in</Button>
      </Inline>
    </Stack>
  );
}
```

### gap.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

const GAPS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] as const;

export default function StackGap() {
  return (
    <Inline align="start" gap={8}>
      {GAPS.map((gap) => (
        <Stack key={gap} gap={1}>
          <Text size="xs" tone="muted">
            Gap {gap}
          </Text>
          <Stack gap={gap}>
            <Badge tone="success">Packed</Badge>
            <Badge tone="warning">Late</Badge>
            <Badge tone="danger">Held</Badge>
          </Stack>
        </Stack>
      ))}
    </Inline>
  );
}
```

### justify.tsx

Example

```tsx
import { Badge } from '@slotted/react/badge';
import { Card, CardBody, CardHeader } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import { Stack } from '@slotted/react/stack';
import { Heading } from '@slotted/react/typography';

const JUSTIFIES = ['start', 'center', 'end', 'between', 'around', 'evenly'] as const;

export default function StackJustify() {
  return (
    <Grid columns={3} gap={4} minItemWidth="xs">
      {JUSTIFIES.map((justify) => (
        <Card key={justify}>
          <CardHeader>
            <Heading level={2} size="sm">
              justify {justify}
            </Heading>
          </CardHeader>
          <CardBody>
            <Stack align="start" gap={2} justify={justify} style={{ blockSize: '12rem' }}>
              <Badge tone="info">Packed</Badge>
              <Badge tone="warning">Shipped</Badge>
              <Badge tone="success">Delivered</Badge>
            </Stack>
          </CardBody>
        </Card>
      ))}
    </Grid>
  );
}
```

### nested.tsx

Example

```tsx
import { Card, CardBody, CardHeader } from '@slotted/react/card';
import { Stack } from '@slotted/react/stack';
import { Heading, Text } from '@slotted/react/typography';

const SECTIONS = [
  { title: 'Payment method', value: 'Visa ending 4242' },
  { title: 'Billing address', value: '200 Harbor Street, Portland' },
  { title: 'Shipping method', value: 'Priority shipping, 2 days' },
] as const;

export default function StackNested() {
  return (
    <Card>
      <CardHeader>
        <Heading level={2} size="md">
          Order SO-10482
        </Heading>
      </CardHeader>
      <CardBody>
        <Stack gap={8}>
          {SECTIONS.map((section) => (
            <Stack key={section.title} gap={2}>
              <Text weight="semibold">{section.title}</Text>
              <Text tone="muted">{section.value}</Text>
            </Stack>
          ))}
        </Stack>
      </CardBody>
    </Card>
  );
}
```
