Flex is a layout component with a very limited subset of the props available to Box and a special prop of its own.
Use this component for flexbox layouts, especially when even spacing between elements is desired (see the gap
prop!).
also known as Row, Stack, Flexbox
Props
Accessibility
Subcomponents
Flex.Item
Use Flex.Item within a Flex container for more precise control over the child element. Flex children that are not explicitly wrapped in Flex.Item will be wrapped in the the component automatically to apply gap
spacing.
Flex.Item Props
Variants
Flex Layout
Flex is strictly for flex layouts. If you're new to flex layout, please read the excellent CSS-Tricks guide to flexbox for a great introduction. Also check out the entertaining Flexbox Froggy game for a fun way to get comfortable with flexbox properties.
Gap
Flex's gap
prop determines spacing between children. Use a single number for equal row and column spacing, or an object to specify different spacing for each direction. For example, use gap={{ row: 2, column: 4 }}
for different spacing between items in rows and columns (regardless of the specified direction
). Or use the gap={3}
shorthand for equal spacing for rows and columns.
Menu
Flex makes flexbox layouts with equally-spaced children a snap!
Applying flex properties to children
When using the gap
prop, Flex wraps each child in a Flex.Item sub-component. If one or more of those children need specific flex properties, you can use Flex.Item directly.
Initial item width using flexBasis
If an item needs a different width in the flex layout than the content would otherwise indicate, flexBasis
can be used.
Overflowing children and minWidth
Extra-wide children can sometimes overflow the Flex parent container, breaking the layout (and skipping truncation, if applicable).
To fix this, simply wrap the wide child in Flex.Item with minWidth={0}
. Voila!
For more info, check out this very helpful blog post.
Component quality checklist
Quality item | Status | Status description |
---|---|---|
Figma Library | Component is not currently available in Figma. | |
Responsive Web | Ready | Component is available in code for web and mobile web. |
iOS | Component is not currently available in code for iOS. | |
Android | Component is not currently available in code for Android. |