Skip to content

Flex

General-purpose flex container — direction, align, justify, wrap, gap, plus grow/shrink/basis as props. The escape hatch when Stack/Inline don't quite fit.

  • stable
  • since v0.1.0
  • 3.71 kB
  • primitive
  • layout
  • flex

Plain <div> by default (polymorphic via as). No semantics beyond what the children carry; pair with <nav>, <main>, <header> via as when the flex container is itself a landmark.

Preview
Open
tsx

direction accepts row (default), column, and the matching *-reverse variants. All four accept a responsive map — a common pattern is direction={{ base: 'column', md: 'row' }} for “stack on mobile, side-by-side on desktop”.

Preview
Open
tsx

The grow, shrink, and basis props are flex-item hints. They apply to the child Boxes (Box, Stack, Inline, Flex, Grid all forward these), letting a child claim or yield space inside a Flex parent without writing custom CSS.

Preview
Open
tsx
PropTypeDefaultDescription
className
string
Additional class names appended after Cynosure's base classes.
style
CSSProperties
Inline style overrides merged last.
children
ReactNode
Flex children.
direction
Responsive<FlexDirection>
Main-axis direction — `row`, `column`, or their reversed variants.
wrap
Responsive<FlexWrap>
`flex-wrap` setting. Use `wrap-reverse` to wrap in the opposite direction.
grow
Responsive<number | `${number}`>
`flex-grow` applied to *this* container (not its children).
shrink
Responsive<number | `${number}`>
`flex-shrink` applied to *this* container (not its children).
basis
Responsive<`${number}px` | `${number}%` | MarginValue>
`flex-basis` applied to *this* container.
gap
Uniform gap in both axes. Falls back to `rowGap`/`columnGap` when set.
rowGap
Gap between wrapped rows. Overrides the row axis of `gap`.
columnGap
Gap between adjacent items on the inline axis. Overrides `gap`'s columns.
align
Responsive<FlexAlign>
Cross-axis alignment — maps to `align-items`. Supports `baseline`.
justify
Responsive<FlexJustify>
Main-axis distribution — maps to `justify-content`.
padding
Padding on all four sides. Token from the spacing scale.
paddingX
Horizontal padding (left + right). Overrides `padding` on the X axis.
paddingY
Vertical padding (top + bottom). Overrides `padding` on the Y axis.
paddingTop
Padding on the top edge. Beats `padding` / `paddingY`.
paddingRight
Padding on the right (inline-end in RTL) edge.
paddingBottom
Padding on the bottom edge.
paddingLeft
Padding on the left (inline-start in RTL) edge.
margin
Margin on all four sides. Accepts the spacing scale or `"auto"`.
marginX
Horizontal margin (left + right). Use `"auto"` to centre.
marginY
Vertical margin (top + bottom).
marginTop
Margin on the top edge.
marginRight
Margin on the right edge.
marginBottom
Margin on the bottom edge.
marginLeft
Margin on the left edge.
width
Element width. Accepts a `SpaceToken`, `LengthValue`, or named alias.
height
Element height. Accepts a `SpaceToken`, `LengthValue`, or named alias.
minWidth
Minimum width — useful for preventing flex children from collapsing.
maxWidth
Maximum width — `"prose"` caps to a comfortable reading measure.
minHeight
Minimum height.
maxHeight
Maximum height.
background
Background colour. Use a `ColorToken` like `"bg.surface"` for theme awareness.
color
Text colour. Inherits unless set.
borderColor
Border colour. Pair with `borderWidth` to make the border visible.
borderWidth
Border thickness in scale steps.
borderStyle
Border line style.
borderRadius
Corner rounding token.
boxShadow
Drop-shadow token from the elevation scale.
opacity
Responsive<number | `${number}`>
Opacity 0–1. Use sparingly — prefer surface tokens over translucency.
overflow
How content that exceeds the box is handled.
overflowX
Horizontal-axis overflow control. Overrides `overflow` for the X axis.
overflowY
Vertical-axis overflow control.
display
CSS `display` value. `"contents"` removes the element's box from layout.
position
CSS `position`. Pair with `top`/`right`/`bottom`/`left` for placement.
top
Top inset (when positioned). Accepts a `SpaceToken`, `"auto"`, `"0"`, or `LengthValue`.
right
Right inset (when positioned).
bottom
Bottom inset (when positioned).
left
Left inset (when positioned).
zIndex
Stacking-context layer token (`"modal"`, `"tooltip"`, …).
gridColumn
Responsive<string>
Grid-column shorthand (e.g. `"1 / 3"`, `"span 2"`).
gridRow
Responsive<string>
Grid-row shorthand.
gridArea
Responsive<string>
Named grid area.
flex
Responsive<"1" | "none" | "auto" | "initial" | (string & {})>
Shorthand: `1 | auto | none | initial | <css>`. Resolves to `flex` on the child.
flexGrow
Responsive<number | `${number}`>
Grow factor inside a flex container.
flexShrink
Responsive<number | `${number}`>
Shrink factor inside a flex container.
flexBasis
Responsive<SizeValue | "content">
Initial main-axis size before grow/shrink.
alignSelf
Override `align-items` for a single child.
justifySelf
Override `justify-items` for a single child (grid).
order
Responsive<number | `${number}`>
Flex/grid child reorder index.
asChild
boolean
When `true`, renders the primitive's single React child via `Slot`, forwarding className/style/ref/event handlers onto it.
as
ElementType
"div"
Rendered intrinsic element or component.
ref
ForwardedRef<Element>
  • For most row/column layouts prefer Inline or Stack — they’re Flex with fewer knobs and clearer intent.
  • “Stack on mobile, side-by-side on desktop”: <Flex direction={{ base: 'column', md: 'row' }} gap="4" />.
  • App shell main area: <Flex direction="column" flex="1" minHeight="0" /> so a nested scroll area can claim the remaining height.