<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

FlexBox

A simple, unstyled container that understands CSS flex layout without the need for adding any custom CSS.

Use FlexBox...

  • To layout content to best organize and fill the available space.
  • To align elements within a container with a specific direction.

Don't use FlexBox...

  • To layout all page content. Use Grid instead.
  • To layout components such as Cards or Standard Tiles. Use Grid instead.
  • To layout form fields. Use Form instead.

The preview has been updated.

Justify Content

Use justifyContent to align items along the primary axis, which is the x-axis by default.

The preview has been updated.

Align Items

Use alignItems to align items along the secondary axis, which is the y-axis by default.

The preview has been updated.

Flex Wrap

Use flexWrap to control whether the items in the FlexBox should wrap to the next line or not.

The preview has been updated.

Flex Direction

Use flexDirection to control whether the items in the FlexBox are laid out in a row or column; this also switches the primary and secondary axis.

The preview has been updated.

Gap

Use gap to put a gutter between the items in the FlexBox. This accepts one of the semantic or numeric space units as values. Note that this controls the inline gap property in the style attribute, so you cannot set the gap via style.

The preview has been updated.

Stack Layout

  • Use Flexbox with flexDirection="column" and the gap property to create vertical stacks of elements with consistent spacing.
  • This approach centralizes spacing control, ensures uniform gutters between children, and avoids hard-coding margins on individual elements.
If you previously used the Emu Stack component, this is the recommended Swan replacement.

Inline Layout

  • For horizontal layouts, Swan usually recommends the Grid component. Grid provides site-standard spacing between items and maintains visual harmony across pages.
  • However, for smaller or more unusual inline layouts, you can use Flexbox with flexDirection="row" and a gap.
If you previously used the Emu Inline component, use Grid where possible, or Flexbox for lightweight cases.

Props

FlexBox
This component is implemented using the <div /> as the root element. You can utilize the native attributes supported by <div /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
alignItemsResponsive<"center" | "end" | "start" | "inherit" | "initial" | "revert" | "unset" | "baseline" | "stretch" | "flex-start" | "flex-end"> | nullfalse
The CSS align-items property sets the align-self value on all direct children as a group. In Flexbox, it controls the alignment of items on the Cross Axis. In Grid Layout, it controls the alignment of items on the Block Axis within their grid area. One of: "stretch", "center", "start", "end", "flex-start", "flex-end", "baseline", "inherit", "initial", "revert", "unset".
null
flexWrapResponsive<"wrap" | "inherit" | "initial" | "revert" | "unset" | "nowrap" | "wrap-reverse"> | nullfalse
The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked. One of: "nowrap", "wrap", "wrap-reverse", "inherit", "initial", "revert", "unset".
null
flexDirectionResponsive<"row" | "inherit" | "initial" | "revert" | "unset" | "row-reverse" | "column" | "column-reverse"> | nullfalse
The flex-direction CSS property sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed). One of: "row", "row-reverse", "column", "column-reverse", "inherit", "initial", "revert", "unset".
null
justifyContentResponsive<"center" | "end" | "start" | "inherit" | "left" | "right" | "normal" | "initial" | "revert" | "unset" | "stretch" | "flex-start" | "flex-end" | "space-between" | "space-around" | "space-evenly"> | nullfalse
The CSS justify-content property defines how the browser distributes space between and around content items along the main-axis of a flex container, and the inline axis of a grid container. One of: "stretch", "center", "start", "end", "flex-start", "flex-end", "left", "right", "normal", "space-between", "space-around", "space-evenly", "inherit", "initial", "revert", "unset".
null
gapResponsive<0 | 1 | "0" | 2 | "1" | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "between-sections" | "between-subsections" | "between-actions" | "to-actions" | "between-icon-and-text"> | nullfalse
The gap property places a uniform gap (gutter) between the flex container's children.
null