# Stack

> React Stack component for Tailwind CSS v4: a padded, wrapping column or row with even gaps, set by boolean props. See when to use Col, Row or Card instead.

Source: https://vaneui.com/docs/layout-components/stack

Import: `import { Stack, Button, Card, Checkbox, Col, Input, Label, PageTitle, Row, Text, Title } from "@vaneui/ui"`

Stack holds a group of items and keeps them clear of its own edges: unlike [Col](/docs/layout-components/col), it comes with `padding` and `flexWrap`. It has no border and square corners, so when the group needs a visible border and rounded corners, use [Card](/docs/layout-components/card), which has both by default. For a single line of items that should not wrap, use [Row](/docs/layout-components/row).

## Basic usage

`Stack` defaults to `column`, `flex`, `gap`, `padding`, `flexWrap`, `md`, `noBorder`, `noInsetRing`, `outline`, and `sharp`: you don't need to pass any of these. Pass `href` to render `Stack` as `<a>` instead of `<div>`. A focus-visible outline auto-enables when `href` is set.

```tsx demo
<Stack>
  <div className="p-4 bg-gray-100 rounded">Item 1</div>
  <div className="p-4 bg-gray-100 rounded">Item 2</div>
  <div className="p-4 bg-gray-100 rounded">Item 3</div>
</Stack>
```

## Stack vs Col

`Stack` and `Col` are both vertical flex columns. The difference is opinion:

- **`Stack`** = `padding: true` + `flexWrap: true`: a padded, wrap-friendly container.
- **`Col`** = `noPadding`: a bare structural column you compose inside other surfaces.

Use `Stack` when the column owns its own breathing room. Use `Col` when an outer `Card` / `Section` / `Container` already supplies the padding.

```tsx demo
<Row itemsStart>
  <Col flex1>
    <Text fontSemibold>Stack (padded by default)</Text>
    <Stack className="border-2 border-dashed border-gray-300">
      <div className="p-3 bg-gray-100 rounded">Item 1</div>
      <div className="p-3 bg-gray-100 rounded">Item 2</div>
    </Stack>
  </Col>
  <Col flex1>
    <Text fontSemibold>Col (no padding)</Text>
    <Col className="border-2 border-dashed border-gray-300">
      <div className="p-3 bg-gray-100 rounded">Item 1</div>
      <div className="p-3 bg-gray-100 rounded">Item 2</div>
    </Col>
  </Col>
</Row>
```

## Direction

Use `row` for horizontal layout. Default is `column` (vertical).

```tsx demo
<Row itemsStart>
  <Col flex1>
    <Text fontSemibold>column (default)</Text>
    <Stack className="border-2 border-dashed border-gray-300">
      <div className="p-3 bg-gray-100 rounded">Item 1</div>
      <div className="p-3 bg-gray-100 rounded">Item 2</div>
    </Stack>
  </Col>
  <Col flex1>
    <Text fontSemibold>row</Text>
    <Stack row className="border-2 border-dashed border-gray-300">
      <div className="p-3 bg-gray-100 rounded">Item 1</div>
      <div className="p-3 bg-gray-100 rounded">Item 2</div>
    </Stack>
  </Col>
</Row>
```

## Spacing

Use size props (`xs`, `sm`, `md`, `lg`, `xl`) to scale gap and padding together, or `noGap` to remove the gap.

```tsx demo
<Row itemsStart>
  <Stack xs flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>xs</Text>
    <div className="p-3 bg-gray-100 rounded">Item 1</div>
    <div className="p-3 bg-gray-100 rounded">Item 2</div>
  </Stack>
  <Stack sm flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>sm</Text>
    <div className="p-3 bg-gray-100 rounded">Item 1</div>
    <div className="p-3 bg-gray-100 rounded">Item 2</div>
  </Stack>
  <Stack flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>md (default)</Text>
    <div className="p-3 bg-gray-100 rounded">Item 1</div>
    <div className="p-3 bg-gray-100 rounded">Item 2</div>
  </Stack>
  <Stack lg flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>lg</Text>
    <div className="p-3 bg-gray-100 rounded">Item 1</div>
    <div className="p-3 bg-gray-100 rounded">Item 2</div>
  </Stack>
  <Stack xl flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>xl</Text>
    <div className="p-3 bg-gray-100 rounded">Item 1</div>
    <div className="p-3 bg-gray-100 rounded">Item 2</div>
  </Stack>
</Row>
```

## Padding sizes

`padding` is on by default. The padding value scales with the size prop. Use `noPadding` to remove it entirely.

```tsx demo
<Row itemsStart>
  <Stack xs filled secondary flex1>
    <Text fontSemibold>xs padding</Text>
    <Card xs>Item</Card>
  </Stack>
  <Stack sm filled secondary flex1>
    <Text fontSemibold>sm padding</Text>
    <Card xs>Item</Card>
  </Stack>
  <Stack filled secondary flex1>
    <Text fontSemibold>md padding (default)</Text>
    <Card xs>Item</Card>
  </Stack>
  <Stack lg filled secondary flex1>
    <Text fontSemibold>lg padding</Text>
    <Card xs>Item</Card>
  </Stack>
  <Stack xl filled secondary flex1>
    <Text fontSemibold>xl padding</Text>
    <Card xs>Item</Card>
  </Stack>
  <Stack noPadding filled secondary flex1>
    <Text fontSemibold>noPadding</Text>
    <Card xs>Item</Card>
  </Stack>
</Row>
```

## Items (cross axis)

Stack has no `items` default, so children stretch to fill the width. Override with `itemsStart`, `itemsCenter`, `itemsEnd`, `itemsBaseline`, or `itemsStretch`.

```tsx demo
<Row itemsStart>
  <Stack flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>default (stretch)</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
  <Stack itemsStart flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>itemsStart</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
  <Stack itemsCenter flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>itemsCenter</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
  <Stack itemsEnd flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>itemsEnd</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
</Row>
```

## Justify (main axis)

Control vertical distribution with `justifyStart`, `justifyEnd`, `justifyCenter`, `justifyBetween`, `justifyAround`, or `justifyEvenly`. The Stack needs a fixed height for these to have any effect.

```tsx demo
<Row itemsStart>
  <Stack justifyStart flex1 className="h-48 border-2 border-dashed border-gray-300">
    <Text fontSemibold>justifyStart</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
  <Stack justifyCenter flex1 className="h-48 border-2 border-dashed border-gray-300">
    <Text fontSemibold>justifyCenter</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
  <Stack justifyEnd flex1 className="h-48 border-2 border-dashed border-gray-300">
    <Text fontSemibold>justifyEnd</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
  <Stack justifyBetween flex1 className="h-48 border-2 border-dashed border-gray-300">
    <Text fontSemibold>justifyBetween</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
  <Stack justifyAround flex1 className="h-48 border-2 border-dashed border-gray-300">
    <Text fontSemibold>justifyAround</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
  <Stack justifyEvenly flex1 className="h-48 border-2 border-dashed border-gray-300">
    <Text fontSemibold>justifyEvenly</Text>
    <div className="p-2 bg-gray-100 rounded">A</div>
    <div className="p-2 bg-gray-100 rounded">B</div>
  </Stack>
</Row>
```

## Wrap behavior

`flexWrap` is on by default. In a horizontal Stack, items wrap to the next line when they would overflow the container. Use `flexNoWrap` to force everything onto a single line.

```tsx demo
<Col>
  <Text fontSemibold>flexWrap (default): items wrap when they overflow</Text>
  <Stack row className="max-w-md border-2 border-dashed border-gray-300">
    <div className="p-3 bg-gray-100 rounded">Item 1</div>
    <div className="p-3 bg-gray-100 rounded">Item 2</div>
    <div className="p-3 bg-gray-100 rounded">Item 3</div>
    <div className="p-3 bg-gray-100 rounded">Item 4</div>
    <div className="p-3 bg-gray-100 rounded">Item 5</div>
  </Stack>
  <Text fontSemibold>flexNoWrap: items shrink to fit</Text>
  <Stack row flexNoWrap className="max-w-md border-2 border-dashed border-gray-300">
    <div className="p-3 bg-gray-100 rounded">Item 1</div>
    <div className="p-3 bg-gray-100 rounded">Item 2</div>
    <div className="p-3 bg-gray-100 rounded">Item 3</div>
    <div className="p-3 bg-gray-100 rounded">Item 4</div>
    <div className="p-3 bg-gray-100 rounded">Item 5</div>
  </Stack>
</Col>
```

## Variants

Use `filled` or `outline` with appearance props for styled containers. Stack defaults to `sharp`: pair with `rounded` or `pill` for curved corners.

```tsx demo
<Row itemsStart>
  <Stack filled primary rounded flex1>
    <Card sm>Filled Primary</Card>
    <Card sm>Item 2</Card>
  </Stack>
  <Stack border success rounded flex1>
    <Card sm success>Outline Success</Card>
    <Card sm success>Item 2</Card>
  </Stack>
</Row>
```

## Text alignment

Use `textLeft`, `textCenter`, `textRight`, or `textJustify` to control text alignment within the stack.

```tsx demo
<Row itemsStart>
  <Stack textLeft flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>Left Aligned</Text>
    <Text>Content aligned to the left.</Text>
  </Stack>
  <Stack textCenter flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>Center Aligned</Text>
    <Text>Content centered within the stack.</Text>
  </Stack>
  <Stack textRight flex1 className="border-2 border-dashed border-gray-300">
    <Text fontSemibold>Right Aligned</Text>
    <Text>Content aligned to the right.</Text>
  </Stack>
</Row>
```

## Responsive layout

Use `mobileStack` or `tabletStack` on a horizontal Stack to switch back to a column on narrower viewports.

```tsx demo
<Stack row tabletStack>
  <Col flex1 className="p-4 bg-primary-100 rounded">
    <Text fontSemibold>Column 1</Text>
    <Text>Horizontal on desktop, stacked on tablet and below.</Text>
  </Col>
  <Col flex1 className="p-4 bg-primary-100 rounded">
    <Text fontSemibold>Column 2</Text>
    <Text>Resize to see the responsive behavior.</Text>
  </Col>
</Stack>
```

## As a form container

Stack's built-in padding makes it a natural container for a form: each `Label` stacks its text above its input, and the Stack provides the vertical rhythm and outer breathing room without any extra wrapper.

```tsx demo
<Stack border rounded className="max-w-sm">
  <Title>Sign in</Title>
  <Label>
    Email
    <Input type="email" placeholder="you@example.com" />
  </Label>
  <Label>
    Password
    <Input type="password" placeholder="********" />
  </Label>
  <Label row itemsCenter>
    <Checkbox />
    Remember me
  </Label>
  <Button filled>Sign in</Button>
</Stack>
```

## As Link

Add `href` to render the Stack as an `<a>` tag, useful for hero cards and large clickable surfaces. A keyboard focus-visible outline auto-renders so the link is reachable via Tab; opt out with `noFocusVisible`.

```tsx demo
<Stack href="/docs/getting-started/installation" border rounded itemsStart className="max-w-md">
  <Zap size={28} />
  <PageTitle>Get started in minutes</PageTitle>
  <Text>Install the package, drop in ThemeProvider, and start shipping.</Text>
  <Button filled>Read the guide</Button>
</Stack>
```

## Next.js Link integration

Use the `tag` prop to render the Stack as a Next.js `Link` for client-side navigation.

```tsx
import Link from 'next/link';
import { Stack, PageTitle, Text, Button } from '@vaneui/ui';

<Stack href="/docs/getting-started" tag={Link} border rounded itemsStart>
  <PageTitle>Get started in minutes</PageTitle>
  <Text>Install the package, drop in ThemeProvider, and start shipping.</Text>
  <Button filled>Read the guide</Button>
</Stack>
```

## Frequently asked questions

### Why does my Stack have less padding on a phone?

`responsiveSizing` is on by default, so a Stack scales its padding and gap down below 1024px and again below 768px, and nested Stacks do not use up a narrow screen. Pass `responsiveSizing={false}` to keep one value at every width, or a smaller size prop to tighten it everywhere. `Section`, `Card`, `Container` and `Modal` scale their padding the same way.

### Why do the items of my Stack sit in two columns?

`flexWrap` is a Stack default, so when the Stack has a fixed or maximum height and its children need more, the extra items wrap into a second column. Pass `flexNoWrap` to keep one column, and add `overflowYAuto` to scroll the overflow instead. Without a height limit the Stack grows with its content and never wraps.

### How do I pad only the sides or only the top and bottom of a Stack?

Use `paddingX` for the left and right sides or `paddingY` for the top and bottom; both scale with the size prop like `padding`. For a single side, such as the top, a class like `pt-6` applies on desktop, and below 1024px the theme's own padding returns on that side. `noPadding` removes all of it.

## Props

| Prop | Category | Default | Description |
| --- | --- | --- | --- |
| `primary` | Appearance |  | Primary color appearance (gray) |
| `accent` | Appearance |  | Accent color appearance (rose) |
| `secondary` | Appearance |  | Secondary color appearance (gray) |
| `tertiary` | Appearance |  | Tertiary color appearance |
| `success` | Appearance |  | Success color appearance (green) |
| `danger` | Appearance |  | Danger color appearance (red) |
| `warning` | Appearance |  | Warning color appearance (amber) |
| `info` | Appearance |  | Info color appearance (cyan) |
| `inheritAppearance` | Appearance |  | Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables |
| `aspectSquare` | Aspect |  | Square box (aspect-ratio: 1 / 1) |
| `aspectVideo` | Aspect |  | Video box (aspect-ratio: 16 / 9) |
| `aspectAuto` | Aspect |  | The content's own ratio (aspect-ratio: auto) |
| `desktopStack` | Breakpoint |  | Stack into a column at desktop width and below (max-desktop: 80rem) |
| `tabletStack` | Breakpoint |  | Stack into a column at tablet width and below (max-tablet: 64rem) |
| `mobileStack` | Breakpoint |  | Stack into a column at mobile width and below (max-mobile: 48rem) |
| `flex1` | Flex |  | Take up remaining space (= `flex-1`, i.e. `flex: 1 1 0%`) |
| `flexAuto` | Flex |  | Grow but respect intrinsic size (= `flex-auto`, i.e. `flex: 1 1 auto`) |
| `flexNone` | Flex |  | Don't grow and don't shrink (= `flex-none`, i.e. `flex: none`) |
| `margin` | Margin |  | Enable margin on all sides |
| `marginX` | Margin |  | Enable only horizontal (inline) margin |
| `marginY` | Margin |  | Enable only vertical (block) margin |
| `marginT` | Margin |  | Enable only top margin |
| `marginB` | Margin |  | Enable only bottom margin |
| `noMargin` | Margin |  | Disable margin (reset to 0) |
| `padding` | Padding | yes | Enable internal padding |
| `paddingX` | Padding |  | Enable only horizontal padding |
| `paddingY` | Padding |  | Enable only vertical padding |
| `noPadding` | Padding |  | Disable internal padding |
| `pill` | Shape |  | Fully rounded corners (circular) |
| `sharp` | Shape | yes | No rounded corners (square) |
| `rounded` | Shape |  | Medium rounded corners (default) |
| `noShrink` | Shrink |  | Prevent the flex item from shrinking below its content size (= `shrink-0`) |
| `xs` | Size |  | Extra small size |
| `sm` | Size |  | Small size |
| `md` | Size | yes | Medium size (default) |
| `lg` | Size |  | Large size |
| `xl` | Size |  | Extra large size |
| `skeleton` | Skeleton |  | Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too |
| `strongBorder` | Strong Border |  | Paint the border in the appearance's strong color instead of its soft one |
| `textLeft` | Text Align |  | Align text to left (physical side, does not flip under RTL) |
| `textCenter` | Text Align |  | Align text to center |
| `textRight` | Text Align |  | Align text to right (physical side, does not flip under RTL) |
| `textJustify` | Text Align |  | Justify text |
| `textStart` | Text Align |  | Align text to the reading-direction start (left in LTR, right in RTL) |
| `textEnd` | Text Align |  | Align text to the reading-direction end (right in LTR, left in RTL) |
| `filled` | Variant |  | Filled variant - solid background with contrasting text color |
| `outline` | Variant | yes | Outline variant - transparent background with border and colored text (default) |
| `ghost` | Variant |  | Ghost variant - transparent background, no border, appearance-colored text, tinted hover background |

Layout and utility props (Border, Display, Flex Direction, Focus Visible, Gap, Height, Hide, Items, Justify, Overflow, Pointer Events, Position, Responsive Sizing, Responsive Width, Ring, Shadow, Show, Transparent, Whitespace, Width, Wrap) are listed on [Common Props](https://vaneui.com/docs/reference/common-props.md).
