---
title: "Stack · UI SDK — StyleX Blocks"
description: "Flex layout primitives (Stack, VStack, HStack) with spacing-token gaps, alignment, justification, and wrap controls."
url: "https://stylexblocks.com/components/ui-sdk/stack/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Stack

Flex layout primitives (Stack, VStack, HStack) with spacing-token gaps, alignment, justification, and wrap controls.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/stack.md), [Base UI](https://stylexblocks.com/components/base-ui/stack.md)
- Category: Layout
- Used in blocks: [AI Chat Conversation](https://stylexblocks.com/block/ui-sdk/ai-chat.md), [AI Chat Landing](https://stylexblocks.com/block/ui-sdk/ai-chat-landing.md), [Analytics Dashboard](https://stylexblocks.com/block/ui-sdk/analytics-dashboard.md), [Basic Login](https://stylexblocks.com/block/ui-sdk/basic-login.md), [Canvas Editor](https://stylexblocks.com/block/ui-sdk/canvas-editor.md), [Card Grid](https://stylexblocks.com/block/ui-sdk/card-grid.md), [Centered Hero](https://stylexblocks.com/block/ui-sdk/centered-hero.md), [Checkout Form](https://stylexblocks.com/block/ui-sdk/checkout-form.md), [Checkout Wizard](https://stylexblocks.com/block/ui-sdk/checkout-wizard.md), [Classic Gallery](https://stylexblocks.com/block/ui-sdk/classic-gallery.md), [Collapsible Table](https://stylexblocks.com/block/ui-sdk/collapsible-table.md), [Comparison Table](https://stylexblocks.com/block/ui-sdk/comparison-table.md), [Contact Form](https://stylexblocks.com/block/ui-sdk/contact-form.md), [Course Detail](https://stylexblocks.com/block/ui-sdk/course-detail.md), [Data Dashboard](https://stylexblocks.com/block/ui-sdk/data-dashboard.md), [Documentation Catalog](https://stylexblocks.com/block/ui-sdk/documentation-catalog.md), [Documentation Design](https://stylexblocks.com/block/ui-sdk/documentation-design.md), [Documentation Technical](https://stylexblocks.com/block/ui-sdk/documentation-technical.md), [Executive Dashboard](https://stylexblocks.com/block/ui-sdk/executive-dashboard.md), [File Explorer](https://stylexblocks.com/block/ui-sdk/file-explorer.md), [Filterable Table](https://stylexblocks.com/block/ui-sdk/filterable-table.md), [Two-Column Form](https://stylexblocks.com/block/ui-sdk/form-two-column.md), [Form Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard.md), [Dialog Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-dialog.md), [Inline Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-inline.md), [Vertical Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-vertical.md), [Funnel & Cohort Dashboard](https://stylexblocks.com/block/ui-sdk/funnel-cohort-dashboard.md), [Gallery Hero](https://stylexblocks.com/block/ui-sdk/gallery-hero.md), [Grouped Table](https://stylexblocks.com/block/ui-sdk/grouped-table.md), [IDE Workspace](https://stylexblocks.com/block/ui-sdk/ide.md), [Inbox Table](https://stylexblocks.com/block/ui-sdk/inbox-table.md), [Incident Console](https://stylexblocks.com/block/ui-sdk/incident-console.md), [Kanban Board](https://stylexblocks.com/block/ui-sdk/kanban-board.md), [Login Card](https://stylexblocks.com/block/ui-sdk/login-card.md), [Login Split](https://stylexblocks.com/block/ui-sdk/login-split.md), [Login SSO](https://stylexblocks.com/block/ui-sdk/login-sso.md), [Messaging Shell](https://stylexblocks.com/block/ui-sdk/messaging-shell.md), [Mixed Gallery](https://stylexblocks.com/block/ui-sdk/mixed-gallery.md), [Order Detail](https://stylexblocks.com/block/ui-sdk/order-detail.md), [Page Editor](https://stylexblocks.com/block/ui-sdk/page-editor.md), [Portfolio Dashboard](https://stylexblocks.com/block/ui-sdk/portfolio-dashboard.md), [Product Detail](https://stylexblocks.com/block/ui-sdk/product-detail.md), [Product Gallery](https://stylexblocks.com/block/ui-sdk/product-gallery.md), [Project Status Dashboard](https://stylexblocks.com/block/ui-sdk/project-status-dashboard.md), [Searchable Table](https://stylexblocks.com/block/ui-sdk/searchable-table.md), [Service Monitoring](https://stylexblocks.com/block/ui-sdk/service-monitoring.md), [Settings Dialog](https://stylexblocks.com/block/ui-sdk/settings-dialog.md), [Settings Form](https://stylexblocks.com/block/ui-sdk/settings-form.md), [Settings Panels](https://stylexblocks.com/block/ui-sdk/settings-panels.md), [Shell Nav](https://stylexblocks.com/block/ui-sdk/shell-nav.md), [Side Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-side-nav.md), [Top Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-top-nav.md), [Side Gallery](https://stylexblocks.com/block/ui-sdk/side-gallery.md), [Simple Table](https://stylexblocks.com/block/ui-sdk/simple-table.md), [Theme Showcase](https://stylexblocks.com/block/ui-sdk/theme-showcase.md), [Tree Table](https://stylexblocks.com/block/ui-sdk/tree-table.md), [Work Item Detail](https://stylexblocks.com/block/ui-sdk/work-item-detail.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/stack/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add stack
```

Equivalent: `npx shadcn add @stylexblocks/stack`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/stack.json

## Usage

```tsx
import { Stack, VStack, HStack } from "#components/ui/ui-sdk/stack.tsx";

export function Example() {
  return (
    <VStack gap="4">
      <HStack gap="2" justify="between">
        <span>Release v4.2</span>
        <span>Ready</span>
      </HStack>

      {/* polymorphic composition via render */}
      <Stack direction="row" gap="3" wrap="wrap">
        <span>Tokens</span>
        <span>Recipes</span>
        <span>Blocks</span>
      </Stack>
    </VStack>
  );
}
```

## Source

`components/ui/ui-sdk/stack.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/ui-sdk/create-component.tsx";
import { defineRecipe } from "#lib/recipe-props.ts";
import { spacing } from "@stylexblocks/ui/tokens/spacing.stylex.ts";

const stackStyles = stylex.create({
  base: {
    display: "flex",
    minWidth: 0,
  },
});

const stackDirections = stylex.create({
  column: { flexDirection: "column" },
  row: { flexDirection: "row" },
  columnReverse: { flexDirection: "column-reverse" },
  rowReverse: { flexDirection: "row-reverse" },
});

const stackGaps = stylex.create({
  "0": { gap: 0 },
  "0.5": { gap: spacing._0_5 },
  "1": { gap: spacing._1 },
  "1.5": { gap: spacing._1_5 },
  "2": { gap: spacing._2 },
  "2.5": { gap: spacing._2_5 },
  "3": { gap: spacing._3 },
  "4": { gap: spacing._4 },
  "5": { gap: spacing._5 },
  "6": { gap: spacing._6 },
  "8": { gap: spacing._8 },
  "10": { gap: spacing._10 },
  "12": { gap: spacing._12 },
});

const stackAligns = stylex.create({
  start: { alignItems: "flex-start" },
  center: { alignItems: "center" },
  end: { alignItems: "flex-end" },
  stretch: { alignItems: "stretch" },
  baseline: { alignItems: "baseline" },
});

const stackJustifies = stylex.create({
  start: { justifyContent: "flex-start" },
  center: { justifyContent: "center" },
  end: { justifyContent: "flex-end" },
  between: { justifyContent: "space-between" },
  around: { justifyContent: "space-around" },
  evenly: { justifyContent: "space-evenly" },
});

const stackWraps = stylex.create({
  nowrap: { flexWrap: "nowrap" },
  wrap: { flexWrap: "wrap" },
  wrapReverse: { flexWrap: "wrap-reverse" },
});

/**
 * Stack — flex layout primitive with spacing-token `gap`, alignment,
 * justification, wrapping, and direction axes. Composition via `render`.
 */
const stackRecipe = defineRecipe({
  styles: stackStyles,
  axes: {
    direction: stackDirections,
    gap: stackGaps,
    align: stackAligns,
    justify: stackJustifies,
    wrap: stackWraps,
  },
  defaultVariants: {
    direction: "column",
    gap: "3",
    align: "stretch",
    justify: "start",
    wrap: "nowrap",
  },
});

export const Stack = createComponent("div", stackRecipe, "Stack");
export type StackProps = React.ComponentProps<typeof Stack>;

/** Vertical stack (`direction="column"`, `align="stretch"`). */
export function VStack(props: Omit<StackProps, "direction">) {
  return <Stack direction="column" align="stretch" {...props} />;
}
VStack.displayName = "VStack";
export type VStackProps = React.ComponentProps<typeof VStack>;

/** Horizontal stack (`direction="row"`, `align="center"`). */
export function HStack(props: Omit<StackProps, "direction">) {
  return <Stack direction="row" align="center" {...props} />;
}
HStack.displayName = "HStack";
export type HStackProps = React.ComponentProps<typeof HStack>;
```
