Space
A flexible layout primitive for arranging content with CSS flexbox.
Space is a small, composable flex layout primitive. It arranges its children horizontally or vertically and exposes the most useful flexbox controls: direction, alignment, justification, wrapping, gaps, sizing, full-width/full-height layouts, semantic tags, and separators.
See the live Space showcase.
Basic usage
<Space gap={12} align="center" justify="space-between">
<span>Project name</span>
<Button>Save</Button>
</Space>Children are rendered in their source order. gap accepts a number in pixels or any CSS length such as 0.75rem, 2vw, or clamp(8px, 2vw, 24px).
Direction and alignment
direction accepts row, row-reverse, column, and column-reverse. align controls the cross axis and accepts normal, stretch, flex-start, flex-end, center, and baseline. justify controls the main axis and accepts normal, flex-start, flex-end, center, space-between, space-around, space-evenly, and stretch.
<Space direction="column" align="stretch" gap="1rem">
<Input label="Email" />
<Input label="Password" />
</Space>Wrapping and responsive layouts
Set wrap="wrap" when children should move onto additional rows. Use wrap="wrap-reverse" to reverse the cross-axis line order. fullWidth sets width: 100%; fullHeight sets height: 100%; inline uses inline-flex.
<Space fullWidth wrap="wrap" gap={8} justify="center">
<Button>One</Button>
<Button>Two</Button>
<Button>Three</Button>
</Space>For different horizontal and vertical spacing, use rowGap and columnGap. These override the corresponding part of gap.
<Space direction="row-reverse" wrap="wrap-reverse" rowGap={16} columnGap="1rem">
<Button>First</Button>
<Button>Second</Button>
<Button>Third</Button>
</Space>row-reverse and column-reverse reverse the main-axis order without changing the source order. wrap-reverse reverses the cross-axis direction of wrapped lines.
Separators and semantic elements
separator inserts the same React content between every pair of children. separatorAriaHidden is true by default because visual separators are usually decorative. Set as to nav, section, ul, ol, or span when another semantic element is more appropriate.
<Space as="nav" aria-label="Breadcrumbs" gap={10} separator={<span>/</span>}>
<Link href="#home">Home</Link>
<Link href="#projects">Projects</Link>
<Link href="#current">Current</Link>
</Space>Flex sizing
flex, grow, shrink, and basis apply flex sizing to the Space container itself when it is a child of another flex container. basis accepts pixels or a CSS length; flex accepts a complete CSS flex value such as 1 or 1 1 320px.
<Space flex="1 1 320px" basis={320} grow={1}>
Flexible content
</Space>For a full-size layout region, combine fullWidth and fullHeight with a parent that has a defined height. Use inline when the flex container should participate in an inline text flow.
<Space fullWidth fullHeight align="center" justify="center">
<span>Centered in the available region</span>
</Space>
<Space inline gap={8} as="nav" aria-label="Inline navigation">
<Link href="#home">Home</Link>
<Link href="#about">About</Link>
</Space>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Elements to arrange. |
direction | 'row' | 'row-reverse' | 'column' | 'column-reverse' | 'row' | Main-axis direction. |
align | 'normal' | 'stretch' | 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'center' | Cross-axis alignment. |
justify | 'normal' | 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch' | 'flex-start' | Main-axis distribution. |
wrap | 'nowrap' | 'wrap' | 'wrap-reverse' | 'nowrap' | Whether items form additional lines. |
gap | number | string | 8px | Default row and column gap. |
rowGap / columnGap | number | string | gap | Independent gaps. |
inline | boolean | false | Uses inline-flex. |
fullWidth / fullHeight | boolean | false | Fills the available width or height. |
flex | string | number | — | CSS flex shorthand for the container. |
grow / shrink | number | 0 / 1 | Flex growth and shrink factors. |
basis | number | string | auto | Initial flex basis. |
separator | ReactNode | — | Content inserted between children. |
separatorAriaHidden | boolean | true | Hides decorative separators from assistive technology. |
as | 'div' | 'span' | 'section' | 'nav' | 'ul' | 'ol' | 'div' | Rendered semantic element. |
className / style | string / CSSProperties | — | Custom class and inline styles. |
All standard HTML attributes for the selected element are also supported, including id, data-*, role, and event handlers.
Accessibility
Space does not add interactive behavior or change the semantics of its children. Choose as="nav" with an accessible label for navigation groups, and use separatorAriaHidden={false} only when the separator conveys meaningful information.