Flex
Flex arranges its children in a row or a column, with even space between them.
Use a Flex for a row of buttons, a toolbar, or a title with actions beside it. For a single column with even spacing, use Stack. To line children up in rows and columns at the same time, use Grid.
Flex is a Box with display: flex, so it accepts the Box props plus direction, align, justify, wrap and gap. It has no grid props, so TypeScript reports an error if you set columns or rows. Use display="inline-flex" to place a Flex inside a line of text.
Set the space between children with gap. Its values are steps on the spacing scale, and the theme's density decides how large each step is. To let one child take the free space, wrap it in a Box with flexGrow="1".
Most props accept either one value or a value for each breakpoint, such as direction={{ initial: "column", md: "row" }}. The breakpoints measure the nearest Box with container, or the whole app when there is none. display accepts one value only, so use a Box if you need it to change with the width.
Flex adds nothing visible and has no role, so a screen reader reads its children in the order you write them. Keep that order the same as the order on screen.
Props
Generated from the types. It lists what this component DECLARES: a prop that arrives from a shared type or from the platform is real and is not repeated here.
| Prop | Type | What it does |
|---|---|---|
backdrop? | boolean | Marks an area where the components sit over other content, such as a toolbar over a canvas or a panel over an image. |
container? | boolean | Make this Box measurable. |
display? | "flex" | "inline-flex" | Set inline-flex to place the flex container in a line of text. |
render? | RenderElement | Renders the box as a different element, so you don't add a wrapper. |
It also takes every prop of a <div>.