Flex
Use Flex to line up a few elements in a row or a column with even gaps: a toolbar, a row of buttons, a label and its control, a stack of cards. When items must line up in columns across rows, or the number of columns changes with the width, use Grid; for the frame of a whole page, use Layout.
Flex lays out its children in a row or a column with an even gap between them. The named gaps come from the theme, so a toolbar or a form row keeps the same rhythm as the rest of the page. It is layout only: it draws nothing of its own.
#Demos
#Basic
A row that wraps when it runs out of room, with the medium gap.
#Vertical and reverse
vertical stacks the items in a column; reverse flips their order in either direction.
vertical
vertical reverse
reverse
#Size
size takes a theme gap (small, medium, large), one number in px for both directions, or [horizontal, vertical] in px.
size="small"
size="medium"
size="large"
size={24}
size={[32, 4]}
#Justify and align
justify distributes the items along the row, align lines them up across it. Try the combinations on items of different heights.
#Wrap
Items wrap onto new lines by default. With wrap={false} they stay on one line; here the items are allowed to shrink to fit. Vertical layouts never wrap.
wrap (default)
wrap={false}
#Inline
inline makes the container inline-flex, so a small group can sit inside a line of text.
#Props
| Name | Type | Default | Description | Version |
|---|---|---|---|---|
size | small | medium | large | number | [number, number] | medium | The gap between items: a theme gap, px for both directions, or [horizontal, vertical] in px. | Unreleased |
justify | start | end | center | flex-start | flex-end | space-between | space-around | space-evenly | start | How items are distributed along the main axis (justify-content). | Unreleased |
align | start | end | center | baseline | stretch | undefined | How items line up across the main axis (align-items). Unset keeps the CSS default, which stretches them. | Unreleased |
vertical | boolean | false | Stacks items in a column. | Unreleased |
reverse | boolean | false | Reverses the order of the items. | Unreleased |
wrap | boolean | true | Wraps items onto new lines when they run out of room. Ignored when vertical. | Unreleased |
inline | boolean | false | Uses inline-flex instead of flex. | Unreleased |
children | ReactNode | undefined | The items. With no children, Flex renders nothing. | Unreleased |
Flex renders a div and also accepts native div attributes and a ref. It adds no role; when the items form a group, such as a set of related actions, give it role="group" and an aria-label.
The named gaps are the --p-flex-gap-small, --p-flex-gap-medium and --p-flex-gap-large theme tokens, each a CSS gap value (row, then column).