Skip to main content
Kaleidoscope

Stack

General purpose layout component with consistent spacing and positioning

Stack is a layout component that acts as an abstraction over flexbox that has all of our spacing tokens baked into it. It allows you to easily add spacing, padding, alignment and positioning to a set of elements.

Default

By default, Stack will set up a flexbox container with elements flowing in a column (i.e.flex-direction: column) with no spacing, padding or other positioning logic.

Editable example

Basic usage

Here's a simple example where we want some buttons set inside a Card, with padding inside the card and even spacing between the buttons.

Editable example

Gap

Gap mirrors the equivalent gap property in CSS flexbox, adding spacing between each element inside the Stack.

Editable example

Padding

Padding applies spacing to the interior of the Stack. It can be applied uniformly or tweaked per-side.

Editable example

Direction

Controls whether elements flow along the horizontal or vertical axis.

Editable example

Responsive values

Padding and gap props all allow setting values to apply at specific responsive breakpoints. This allows you to customise gap and padding to fit different screen sizes better.

Here's an example that changes the gap spacing between the ExampleContent elements based on viewport, and the padding inside each ExampleContent:

Editable example

Usage with Figma designs

Stack also works really well with auto-layout in Figma, you can directly plug in the spacing tokens as padding/gap values from dev mode.

A screenshot from Figma, showing the layout settings that can be used with Stack to match the design

Note you’ll only get the nice s, m, l values if the design is using auto-layout (and the designer has selected a spacing var for all the gaps/padding), which we don’t always use for everything. If you see raw pixel values you’ll still need to translate them to use the .