Skip to main content

Flex

Flex is an explicit flexbox container with shorthand props for common flexbox properties. It provides more granular control than Stack.

Open in Storybook

Import​

import { Flex } from "@tosui/react";

Basic usage​

Direction​

Column 1
Column 2
First (shows last)
Second (shows first)

Alignment​

Left
Center
Right

Responsive direction​

First
Second (grows on desktop)

Wrapping​

Item 1
Item 2
Item 3
Item 4
Item 5

Flex item properties​

Flex supports grow, shrink, and basis for controlling the flex container itself.

<Flex grow={1} shrink={0} basis="200px">
This flex container will grow to fill space
</Flex>

Separate row and column gaps​

Item 1
Item 2
Item 3
Item 4

Props reference​

All convenience props (direction, align, justify, wrap, alignSelf) accept responsive objects in addition to simple values.

PropTypeDefaultDescription
directionResponsiveValue<"row" | "column" | "row-reverse" | "column-reverse">"row"Flex direction
wrapResponsiveValue<"nowrap" | "wrap" | "wrap-reverse">"nowrap"Flex wrap behavior
justifyResponsiveValue<"start" | "center" | "end" | "space-between" | "space-around" | "space-evenly">-Main-axis alignment
alignResponsiveValue<"start" | "center" | "end" | "stretch" | "baseline">-Cross-axis alignment
alignContentResponsiveValue<"start" | "center" | "end" | "space-between" | "space-around" | "space-evenly">-Multi-line alignment
gapResponsiveValue<0-32>-Gap between children
gapRowResponsiveValue<0-32>-Row gap
gapColumnResponsiveValue<0-32>-Column gap
basisstring-Flex basis
grownumber-Flex grow
shrinknumber-Flex shrink
alignSelfResponsiveValue<"auto" | "start" | "center" | "end" | "stretch" | "baseline">-Self alignment in parent flex
asElementType"div"HTML element to render

TypeScript​

import { Flex, type FlexProps, type FlexOwnProps } from "@tosui/react";