Description
The Flex component is a layout component that provides a simple and intuitive API for creating flexbox layouts. It offers props for all common flexbox properties including direction, alignment, justification, wrapping, and gap spacing.Props
Flex extends all standard HTML div attributes through Base UI’suseRender hook and accepts the following variant props:
Controls the direction of flex items
row- Items are placed horizontally (default)column- Items are placed verticallyrowReverse- Items are placed horizontally in reverse ordercolumnReverse- Items are placed vertically in reverse order
Controls alignment of items along the cross axis
start- Items align to the start of the cross axiscenter- Items are centered along the cross axisend- Items align to the end of the cross axisstretch- Items stretch to fill the container (default)baseline- Items align along their baseline
Controls alignment of items along the main axis
start- Items align to the start (default)center- Items are centeredend- Items align to the endbetween- Items have space distributed between them
Controls whether flex items wrap to new lines
noWrap- All items stay on one line (default)wrap- Items wrap to new lines as neededwrapReverse- Items wrap to new lines in reverse order
gap
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 'extra-small' | 'small' | 'medium' | 'large' | 'extra-large'
Controls spacing between flex items using design system tokensNumeric values (1-9):
- Maps to
--rs-space-1through--rs-space-9
extra-small- Uses--rs-space-2small- Uses--rs-space-3medium- Uses--rs-space-5large- Uses--rs-space-9extra-large- Uses--rs-space-11
Controls the width of the flex container
full- Sets width to 100%
Additional CSS class names to apply to the Flex container
Custom render function from Base UI for advanced rendering control
A ref to access the underlying div element
Usage examples
Basic horizontal layout
Vertical layout
Centered content
With gap spacing
Space between items
Wrapping layout
Full width container
Reverse direction
Styling notes
The Flex component uses CSS modules and applies the following base styles:display: flex- Base flexbox displaybox-sizing: border-box- Consistent box model
direction="row"→flex-direction: rowdirection="column"→flex-direction: columndirection="rowReverse"→flex-direction: row-reversedirection="columnReverse"→flex-direction: column-reverse
align="start"→align-items: flex-startalign="center"→align-items: centeralign="end"→align-items: flex-endalign="stretch"→align-items: stretchalign="baseline"→align-items: baseline
justify="start"→justify-content: flex-startjustify="center"→justify-content: centerjustify="end"→justify-content: endjustify="between"→justify-content: space-between
wrap="noWrap"→flex-wrap: nowrapwrap="wrap"→flex-wrap: wrapwrap="wrapReverse"→flex-wrap: wrap-reverse