<Flex><Flex><BoxbackgroundColor="colorBackgroundPrimaryWeak"padding="space40">Left area</Box></Flex><Flex grow><BoxbackgroundColor="colorBackgroundPrimaryWeaker"padding="space40"width="100%">Right area</Box></Flex></Flex>
Flex is a layout component that allows you to build flexbox based elements and layouts. These flexible elements and layouts allow your components to adapt to the available space or screen size.
Flex utilizes a simplified flexbox API that allows you more efficient ways to layout, align, and distribute space among elements in a container. The Flex API helps take the confusion out of using flexbox CSS properties, by giving you simple methods to change properties like flex, flex-direction, flex-wrap, and so on.
Flexible elements can adapt to fill space within the layout. This allows Flex to work well for product layouts or elements that change orientation, resize, stretch, or shrink.
The Flex API was created because flexbox can be a difficult CSS property to wrap your head around, which leads to confusion on how it all works. If you’d like to learn more about flexbox, the learning resources below provide further information:
The Flex component is an all purpose component. By default, it has no accessibility concerns. If you use the Flex as a custom element, it is up to you to manage the resulting accessibility implications.
<Flex><Flex><BoxbackgroundColor="colorBackgroundPrimaryWeak"padding="space40">Left area</Box></Flex><Flex grow><BoxbackgroundColor="colorBackgroundPrimaryWeaker"padding="space40"width="100%">Right area</Box></Flex></Flex>
<Flex><Flex grow shrink basis="1px"><BoxbackgroundColor="colorBackgroundPrimaryWeak"padding="space40"width="100%">Left area</Box></Flex><Flex grow shrink basis="1px"><BoxbackgroundColor="colorBackgroundPrimaryWeaker"padding="space40"width="100%">Right area</Box></Flex></Flex>
<Flex vertical><Flex grow><BoxbackgroundColor="colorBackgroundPrimaryWeak"padding="space40"width="100%">Left area</Box></Flex><Flex grow><BoxbackgroundColor="colorBackgroundPrimaryWeaker"padding="space40"width="100%">Right area</Box></Flex></Flex>
<Flex wrap><Flex basis="800px"><BoxbackgroundColor="colorBackgroundPrimaryWeak"padding="space40"width="100%">Left area</Box></Flex><Flex><BoxbackgroundColor="colorBackgroundPrimaryWeaker"padding="space40"width="100%">Right area</Box></Flex></Flex>
<Flex vAlignContent="center"><Flex grow><BoxbackgroundColor="colorBackgroundPrimaryWeak"padding="space40"width="100%">Left area</Box></Flex><Flex grow><BoxbackgroundColor="colorBackgroundPrimaryWeaker"padding="space40"width="100%"height="size10">Right area</Box></Flex></Flex>
<Flex hAlignContent="center" vertical><Flex><BoxbackgroundColor="colorBackgroundPrimaryWeak"padding="space40"width="100%">Left area</Box></Flex><Flex><BoxbackgroundColor="colorBackgroundPrimaryWeaker"padding="space40"width="size30">Right area</Box></Flex></Flex>
The Flex component is used to compose flexible layout experiences. Let's look at an example where we need to build a flexible content layout with two sidebars: its has a left sidebar, a content area, and a right sidebar. Here's how we’ll compose the flexible layout using Flex:
<Flex><Flex><BoxbackgroundColor="colorBackgroundPrimaryWeak"padding="space40"height="size20">Left sidebar area</Box></Flex><Flex grow><BoxbackgroundColor="colorBackgroundPrimaryWeaker"padding="space40"width="100%"height="size20">Content area</Box></Flex><Flex><BoxbackgroundColor="colorBackgroundPrimaryWeak"padding="space40"height="size20">Right sidebar area</Box></Flex></Flex>
The Flex component should be used when a flexible layout is needed with a page layout or custom component layout.
Do
Use Flex to layout your page or custom component.
Don't
Use Flex to set margins or padding within layouts and components.
Do
Use Flex to build responsive experiences.
Don't
Use inline CSS or classNames to add styles that Flex can provide.