Skip to content
Browse documentation
whisk/ui

Spacer

Distribute space between flex children.

Overview

Spacer is an empty, decorative flex item that grows to use the remaining main-axis space between content groups.

Use when

A flex layout has three or more items, or only some items need remaining space to push content apart.

Use instead

Use justify="between" for exactly two groups. Use gap for space between every sibling, and padding or margin for document spacing.

Usage

Project

import { Button, Spacer, StackRow, Text } from "@smoothie-framework/whisk-react";

<StackRow>
  <Text weight="semibold">Project</Text>
  <Spacer />
  <Button variant="secondary">Share</Button>
  <Button>Save</Button>
</StackRow>

Examples

Vertical layout

Spacer grows along the parent's main axis. In a vertical Stack, give the parent a height before expecting Spacer to push content to the bottom.

Deployment ready

Review the changes before publishing.

import { Box, Button, Spacer, Stack, Text } from "@smoothie-framework/whisk-react";

<Box height={40} padding={3} background="surface1" rounded="md">
  <Stack height="full" gap={2}>
    <Text weight="semibold">Deployment ready</Text>
    <Text color="subtle">Review the changes before publishing.</Text>
    <Spacer />
    <Button>Publish</Button>
  </Stack>
</Box>

Weight

Two Spacers divide remaining flex space by their grow values. Keep this for a deliberate layout relationship, not routine sibling spacing.

Start

Middle

End

import { Spacer, StackRow, Text } from "@smoothie-framework/whisk-react";

<StackRow align="center">
  <Text>Start</Text>
  <Spacer grow={2} />
  <Text>Middle</Text>
  <Spacer />
  <Text>End</Text>
</StackRow>

Gap

Spacer separates groups. When every item needs the same distance, use a container gap instead.

import { Button, StackRow } from "@smoothie-framework/whisk-react";

<StackRow gap={3}>
  <Button variant="secondary">Cancel</Button>
  <Button>Save changes</Button>
</StackRow>

Props

Component props

PropTypeDefaultDescription
grownumber1Set the native flex-grow weight. It must be a finite, non-negative number.
shrinknumber1Set the native flex-shrink weight. It must be a finite, non-negative number.
basisnumber | string0Set the initial flex basis with a static utility value.
alignSelfauto | start | center | end | stretchstretchOverride the Spacer's alignment on a flex container's cross axis.
justifySelfauto | start | center | end | stretchstretchSet grid self-alignment. It does not affect an item in a flex layout.

Shared props

PropSupportedNotes
as / asChildNoSpacer always renders its decorative div host.
Style propsYesStatic style props are supported; component props take precedence. See Style props.
className / styleYesApplied to the decorative div.
refYesForwards to the decorative div.
Native HTML attributesNoOnly id and style are forwarded; other native attributes aren't.

Accessibility

Spacer is always hidden from assistive technology and cannot receive children or focus. Use it only to distribute a flex layout, never to create reading order, visual hierarchy, or document spacing.