Skip to main content

Stack

The Stack component organizes elements along the block (vertical) or inline (horizontal) axis. Use it to structure layouts and control spacing between elements.

The component automatically manages spacing through gap properties and supports flexible alignment and wrapping behavior. Complex grid-like layouts may require multiple nested Stack components or alternative layout approaches.

Use cases

  • Layout arrangement: Arrange form elements, buttons, or content in vertical or horizontal layouts.
  • Responsive design: Create layouts that adapt to different screen sizes and orientations.
  • Spacing control: Control spacing between elements using gap properties for visual hierarchy.
  • Content alignment: Align content precisely using justify and align properties.

Organize elements using a Stack component. This example shows a basic stack with spacing between child elements.

Organize elements with a stack

Organize elements with a stack

<s-stack gap="small" direction="inline" justifyContent="center">
<s-badge tone="neutral">Paid</s-badge>
<s-badge tone="success">Active</s-badge>
</s-stack>

Configure the following properties on the Stack component.

Anchor to alignContent
alignContent

Aligns the Stack along the cross axis.

Anchor to alignItems
alignItems

Aligns the Stack's children along the cross axis.

Anchor to blockSize
blockSize
Default: 'auto'

Adjust the block size. Mobile surfaces: Avoid using percentage-based sizes. They do not behave as expected when placed within a scrollable container.

Anchor to columnGap
columnGap
"" |
Default: '' - meaning no override

Adjust spacing between elements in the inline axis. This overrides the column value of gap.

Anchor to direction
direction
"block" | "inline"
Default: 'block'

Sets how the children are placed within the Stack. This uses logical properties.

<>
Default: 'none'

Adjust spacing between elements. A single value applies to both axes. A pair of values (eg large-100 large-500) can be used to set the inline and block axes respectively.

string

A unique identifier for the element.

Anchor to inlineSize
inlineSize
Default: 'auto'

Adjust the inline size.

Anchor to justifyContent
justifyContent
Default: 'normal'

Aligns the Stack along the main axis.

Anchor to maxBlockSize
maxBlockSize
Default: 'none'

Adjust the maximum block size. Mobile surfaces: Avoid using percentage-based sizes. They do not behave as expected when placed within a scrollable container.

Anchor to maxInlineSize
maxInlineSize
Default: 'none'

Adjust the maximum inline size. Mobile surfaces: Avoid using percentage-based sizes. They do not behave as expected when placed within a scrollable container.

Anchor to minBlockSize
minBlockSize
Default: '0'

Adjust the minimum block size. Mobile surfaces: Avoid using percentage-based sizes. They do not behave as expected when placed within a scrollable container.

Anchor to minInlineSize
minInlineSize
Default: '0'

Adjust the minimum inline size. Mobile surfaces: Avoid using percentage-based sizes. They do not behave as expected when placed within a scrollable container.

Anchor to padding
padding
<>
Default: 'none'

Adjust the padding of all edges.

1-to-4-value syntax is supported. Note that, contrary to the CSS, it uses flow-relative values and the order is:

  • 4 values: block-start inline-end block-end inline-start
  • 3 values: block-start inline block-end
  • 2 values: block inline

For example:

  • large means block-start, inline-end, block-end and inline-start paddings are large.
  • large none means block-start and block-end paddings are large, inline-start and inline-end paddings are none.
  • large none large means block-start padding is large, inline-end padding is none, block-end padding is large and inline-start padding is none.
  • large none large small means block-start padding is large, inline-end padding is none, block-end padding is large and inline-start padding is small.

A padding value of auto will use the default padding for the closest container that has had its usual padding removed.

Anchor to paddingBlock
paddingBlock
<"" | >
Default: '' - meaning no override

Adjust the block-padding.

  • large none means block-start padding is large, block-end padding is none.

This overrides the block value of padding.

Anchor to paddingBlockEnd
paddingBlockEnd
"" |
Default: '' - meaning no override

Adjust the block-end padding.

This overrides the block-end value of paddingBlock.

Anchor to paddingBlockStart
paddingBlockStart
"" |
Default: '' - meaning no override

Adjust the block-start padding.

This overrides the block-start value of paddingBlock.

Anchor to paddingInline
paddingInline
<"" | >
Default: '' - meaning no override

Adjust the inline padding.

  • large none means inline-start padding is large, inline-end padding is none.

This overrides the inline value of padding.

Anchor to paddingInlineEnd
paddingInlineEnd
"" |
Default: '' - meaning no override

Adjust the inline-end padding.

This overrides the inline-end value of paddingInline.

Anchor to paddingInlineStart
paddingInlineStart
"" |
Default: '' - meaning no override

Adjust the inline-start padding.

This overrides the inline-start value of paddingInline.

Anchor to rowGap
rowGap
"" |
Default: '' - meaning no override

Adjust spacing between elements in the block axis. This overrides the row value of gap.

  • Choose appropriate direction: Use block for vertical arrangements like forms. Use inline for horizontal arrangements like button groups. Note that inline wraps while block doesn't.
  • Use design system spacing: Use SpacingKeyword values for consistency. Start with base and adjust as needed.
  • Apply alignment properties: Use justifyContent for main axis distribution, alignItems for cross axis positioning, alignContent for extra space distribution.
  • Avoid percentages on mobile: Don't use percentage-based sizing within scrollable containers on mobile surfaces.
  • Use gap for spacing control: Use gap for uniform spacing, rowGap for block axis, columnGap for inline axis.
Was this page helpful?