Flex

A flex layout container for alignment.
Importimport{ Flex }from"antd";
Versionsupported since 5.10.0

When To Use

  • Good for setting spacing between elements.
  • Suitable for setting various horizontal and vertical alignments.

Difference with Space component

  • Space is used to set the spacing between inline elements. It will add a wrapper element for each child element for inline alignment. Suitable for equidistant arrangement of multiple child elements in rows and columns.
  • Flex is used to set the layout of block-level elements. It does not add a wrapper element. Suitable for layout of child elements in vertical or horizontal direction, and provides more flexibility and control.

Examples

The basic usage.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Select justify :

Select align :

Set align.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Set the gap between elements, which has three preset sizes: small, middle, large, You can also customize the gap size.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Auto wrap line.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
avatar

“antd is an enterprise-class UI design language and React UI library.”

Get Started

Nesting can achieve more complex layouts.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

API

This component is available since antd@5.10.0. The default behavior of Flex in horizontal mode is to align upward, In vertical mode, aligns the stretch, You can adjust this via properties.

Common props ref:Common props

PropertyDescriptiontypeDefaultVersion
verticalIs direction of the flex vertical, use flex-direction: columnbooleanfalse
wrapSet whether the element is displayed in a single line or in multiple linesflex-wrap | booleannowrapboolean: 5.17.0
justifySets the alignment of elements in the direction of the main axisjustify-contentnormal
alignSets the alignment of elements in the direction of the cross axisalign-itemsnormal
flexflex CSS shorthand propertiesflexnormal
gapSets the gap between gridssmall | middle | large | string | number-
componentcustom element typeReact.ComponentTypediv

Design Token

Global TokenHow to use?