Concepts
OverviewCompositionTestingLayout
Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrapComponents
AccordionAdmonitionAvatarButtonCheckboxComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsProgressPrompt ModalRadioRatingSelectSwitchTableTabsTagTextTextareaToggleTooltipUtilities
Feature FlagsForLocal StoragePortalShowsplitPropsTheme1import { Flex, Box } from "styled-system/jsx";2
3const Demo = () => {4 return (5 <Flex>6 <Box bgColor="page.surface.100" h="3rem" />7 <Box bgColor="page.surface.100" h="3rem" />8 <Box bgColor="page.surface.100" h="3rem" />9 </Flex>10 );11};
Usage
1import { Flex } from "styled-system/jsx";
1<Flex>2 <div />3 <div />4</Flex>
Examples
Direction
Use the direction
or flexDirection
prop to change the direction of the flex
1import { Flex } from "styled-system/jsx";2import { DecorativeBox } from "compositions/lib/decorative-box"3
4const Demo = () => {5 return (6 <Flex gap="4" direction="column">7 <DecorativeBox height="10" />8 <DecorativeBox height="10" />9 <DecorativeBox height="10" />10 </Flex>11 )12}
Align
Use the align
or alignItems
prop to align the children along the cross axis.
1import { Flex } from "styled-system/jsx";2import { DecorativeBox } from "compositions/lib/decorative-box"3
4const Demo = () => {5 return (6 <Flex gap="4" align="center">7 <DecorativeBox height="10" />8 <DecorativeBox height="10" />9 <DecorativeBox height="10" />10 </Flex>11 )12}
Justify
Use the justify
or justifyContent
prop to align the children along the main
axis.
1import { Flex } from "styled-system/jsx";2import { DecorativeBox } from "compositions/lib/decorative-box"3
4const Demo = () => {5 return (6 <Flex gap="4" justify="space-between">7 <DecorativeBox height="10" />8 <DecorativeBox height="10" />9 <DecorativeBox height="10" />10 </Flex>11 )12}
Order
Use the order
prop to change the order of the children.
1import { Flex } from "styled-system/jsx";2import { DecorativeBox } from "compositions/lib/decorative-box"3
4const Demo = () => {5 return (6 <Flex gap="4">7 <DecorativeBox height="10" order={2} />8 <DecorativeBox height="10" order={1} />9 <DecorativeBox height="10" order={3} />10 </Flex>11 )12}
Auto Margin
Apply margin to a flex item to push it away from its siblings.
1import { Flex } from "styled-system/jsx";2import { DecorativeBox } from "compositions/lib/decorative-box"3
4const Demo = () => {5 return (6 <Flex gap="4" justify="space-between">7 <DecorativeBox height="10" width="40" />8 <DecorativeBox height="10" width="40" marginEnd="auto" />9 <DecorativeBox height="10" width="40" />10 </Flex>11 )12}
Wrap
Use the wrap
or flexWrap
prop to wrap the children when they overflow the
parent.
1import { Flex } from "styled-system/jsx";2import { DecorativeBox } from "compositions/lib/decorative-box"3
4const Demo = () => {5 return (6 <Flex gap="4" wrap="wrap" maxW="500px">7 <DecorativeBox height="10" width="200px" />8 <DecorativeBox height="10" width="200px" />9 <DecorativeBox height="10" width="200px" />10 </Flex>11 )12}
Props
The Flex
component accepts any CSS properties and the following props:
Prop | Type | Description |
---|---|---|
align | SystemStyleObject['alignItems'] | The alignment of the children along the cross axis. |
direction | SystemStyleObject['flexDirection'] | The flex direction. |
justify | SystemStyleObject['justifyContent'] | The alignment of the children along the main axis. |
wrap | SystemStyleObject['flexWrap'] | The wrapping behavior of the children. |
basis | SystemStyleObject['flexBasis'] | The flex behavior of the children. |
grow | SystemStyleObject['flexGrow'] | The flex grow behavior of the children. |
shrink | SystemStyleObject['flexShrink'] | The flex shrink behavior of the children. |
inline | boolean | If true, the flex container will be displayed as inline-flex . |
On this page