Skip to content
Browse documentation
whisk/ui

Flex

Arrange content with direct flex layout controls.

Overview

Flex is the low-level layout primitive for arranging children along one axis with direct control over direction, alignment, distribution, wrapping, and flexible space.

Compare the layout primitives in the Choose a layout component table.

Use when

You need direct flexbox control for a row or column that wraps, distributes its children, or changes axis responsively.

Use instead

Use Stack, StackRow, or StackCol for ordinary one-dimensional content rhythm. Use Grid when both columns and rows matter.

Usage

Workspace

Updated now

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

<Flex gap={3} align="center" justify="between">
  <Text>Workspace</Text>
  <Text color="subtle">Updated now</Text>
</Flex>

Examples

Direction

Use a responsive direction when the same content should become a row only after there is enough inline space.

Box 1

Box 2

Box 3

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

<Flex direction={{ base: "column", md: "row" }} gap={2}>
  <Box padding={3} background="surface2" rounded="md">
    <Text>Box 1</Text>
  </Box>
  <Box padding={3} background="surface2" rounded="md">
    <Text>Box 2</Text>
  </Box>
  <Box padding={3} background="surface2" rounded="md">
    <Text>Box 3</Text>
  </Box>
</Flex>

Align

Use align to position children on the cross axis. In a row, that is the vertical axis.

Box 1

Box 2

Box 3

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

<Flex height={24} align="center" gap={2} padding={2} background="surface1" rounded="md">
  <Box padding={2} background="surface2" rounded="md">
    <Text>Box 1</Text>
  </Box>
  <Box padding={4} background="surface2" rounded="md">
    <Text>Box 2</Text>
  </Box>
  <Box padding={2} background="surface2" rounded="md">
    <Text>Box 3</Text>
  </Box>
</Flex>

Justify

Use justify to distribute children on the main axis. In a row, that is the horizontal axis.

start

Box 1

Box 2

center

Box 1

Box 2

end

Box 1

Box 2

between

Box 1

Box 2

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

<Stack gap={3}>
  <Text size="sm" color="subtle">start</Text>
  <Flex background="surface1" rounded="lg" justify="start" gap={2}>
    <Box padding={2} background="surface2" rounded="md">
      <Text>Box 1</Text>
    </Box>
    <Box padding={2} background="surface2" rounded="md">
      <Text>Box 2</Text>
    </Box>
  </Flex>
  <Text size="sm" color="subtle">center</Text>
  <Flex background="surface1" rounded="lg" justify="center" gap={2}>
    <Box padding={2} background="surface2" rounded="md">
      <Text>Box 1</Text>
    </Box>
    <Box padding={2} background="surface2" rounded="md">
      <Text>Box 2</Text>
    </Box>
  </Flex>
  <Text size="sm" color="subtle">end</Text>
  <Flex background="surface1" rounded="lg" justify="end" gap={2}>
    <Box padding={2} background="surface2" rounded="md">
      <Text>Box 1</Text>
    </Box>
    <Box padding={2} background="surface2" rounded="md">
      <Text>Box 2</Text>
    </Box>
  </Flex>
  <Text size="sm" color="subtle">between</Text>
  <Flex background="surface1" rounded="lg" justify="between">
    <Box padding={2} background="surface2" rounded="md">
      <Text>Box 1</Text>
    </Box>
    <Box padding={2} background="surface2" rounded="md">
      <Text>Box 2</Text>
    </Box>
  </Flex>
</Stack>

Grow

TextInput does not accept the grow style prop, so wrap it in a growing Box when it should take the space left by a fixed action.

import { Box, Button, Flex, TextInput } from "@smoothie-framework/whisk-react";

<Flex gap={2}>
  <Box grow={1}>
    <TextInput aria-label="Search projects" placeholder="Search projects" />
  </Box>
  <Button>Search</Button>
</Flex>

Wrap

Set wrap when a row can contain more items than a narrow viewport can hold. Keep a gap so wrapped items remain distinct.

1
2
3
4
5
6
import { Box, Flex } from "@smoothie-framework/whisk-react";

<Flex width="full" wrap gap={2}>
  <Box width={16} height={16} background="surface2" rounded="md">1</Box>
  <Box width={24} height={16} background="surface2" rounded="md">2</Box>
  <Box width={32} height={16} background="surface2" rounded="md">3</Box>
  <Box width={48} height={16} background="surface2" rounded="md">4</Box>
  <Box width={56} height={16} background="surface2" rounded="md">5</Box>
  <Box width={64} height={16} background="surface2" rounded="md">6</Box>
</Flex>

Props

Component props

PropTypeDefaultDescription
directionResponsive<row | column | row-reverse | column-reverse>rowSet the main axis and its order.
gapResponsive<SpacingStep>0Set space between sibling items from the spacing scale.
alignResponsive<start | center | end | stretch | baseline>stretchAlign children on the cross axis.
justifyResponsive<start | center | end | between | around | evenly>startDistribute children along the main axis.
wrapResponsive<boolean>falseAllow children to move onto another line when the container runs out of space.
inlinebooleanfalseRender an inline flex container instead of a block flex container.

Shared props

PropSupportedNotes
as / asChildYesChoose the rendered host with as, or merge the component props into one child with asChild.
Style propsYesUse the shared static style-prop surface. See Style props.
className / styleYesApplied to the rendered host.
refYesForwards to the rendered host.
Native HTML attributesYesNative attributes are forwarded to the rendered host.

Accessibility

Flex is a layout primitive. It does not create a list, group, or landmark. Keep the DOM order equal to the visual order so keyboard and screen-reader users encounter content predictably. Avoid reverse directions when that order matters: they change the visual order without changing the DOM order. Flex does not provide an item-order prop.