Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Layout & primitives

Flex

Free1.8 KB gzipped

Full flexbox container: direction (fixed or responsive), wrapping, alignment on both axes, line distribution, and token-based gaps.

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · No keyboard interaction of its own · Full report

Import

tsx
import { Flex } from "@vjdesigns/vjdesigns-ui";

Importing only Flex adds about 1.8 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.

Examples

Alignment

Props map to flexbox, with spacing steps for gap.

JL

Jordan Lee

jordan@example.com

Owner
tsx
import { Avatar, Badge, Box, Flex, Text } from "@vjdesigns/vjdesigns-ui";

export function Alignment() {
  return (
    <Flex justify="between" align="center" gap={4} wrap="wrap" style={{ width: "100%", maxWidth: "30rem" }}>
      <Flex align="center" gap={3}>
        <Avatar name="Jordan Lee" colorFromName />
        <Box>
          <Text weight="semibold">Jordan Lee</Text>
          <Text size="sm" tone="muted">
            jordan@example.com
          </Text>
        </Box>
      </Flex>
      <Badge tone="success">Owner</Badge>
    </Flex>
  );
}

Responsive

Any layout prop takes one value per breakpoint. This row stacks on narrow screens.

grow

auto

tsx
import { Box, Button, Flex, Text } from "@vjdesigns/vjdesigns-ui";

export function Responsive() {
  return (
    <Flex direction={{ base: "column", sm: "row" }} gap={{ base: 2, sm: 4 }} style={{ width: "100%" }}>
      <Flex.Item grow>
        <Box tone="primary" radius="md" p={4}>
          <Text weight="semibold" tone="inherit">
            grow
          </Text>
        </Box>
      </Flex.Item>
      <Box tone="neutral" radius="md" p={4}>
        <Text weight="semibold" tone="inherit">
          auto
        </Text>
      </Box>
      <Button>Action</Button>
    </Flex>
  );
}

Accessibility

Keep the visual order the same as the source order (SC 1.3.2 and 2.4.3): keyboard and screen reader users follow the source. Place items with justify and align rather than order or reversed directions.

Total

$42.00

tsx
import { Box, Button, Flex, Text } from "@vjdesigns/vjdesigns-ui";

export function Accessibility() {
  return (
    <Box border radius="lg" p={4} style={{ width: "100%", maxWidth: "24rem" }}>
      <Flex justify="between" align="center">
        <Text>Total</Text>
        <Text weight="bold">$42.00</Text>
      </Flex>
      <Flex justify="end" gap={2} style={{ marginTop: "1rem" }}>
        <Button variant="ghost" tone="neutral">
          Back
        </Button>
        <Button>Pay</Button>
      </Flex>
    </Box>
  );
}

Translated

In Arabic a row runs right to left on its own: the first item sits on the right and justify="end" means the left edge. The DOM order stays the same, so reading order does too.

الإجمالي

42.00 $

tsx
import {
  Box,
  Button,
  Flex,
  Text,
  LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";

export function Translated() {
  return (
    <LocaleProvider locale="ar" messages={ar}>
      <Box border radius="lg" p={4} style={{ width: "100%", maxWidth: "24rem" }}>
        <Flex justify="between" align="center">
          <Text>الإجمالي</Text>
          <Text weight="bold">42.00 $</Text>
        </Flex>
        <Flex justify="end" gap={2} style={{ marginTop: "1rem" }}>
          <Button variant="ghost" tone="neutral">
            رجوع
          </Button>
          <Button>ادفع</Button>
        </Flex>
      </Box>
    </LocaleProvider>
  );
}

Usage notes

Use Stack for the common case of evenly spaced children in one direction. Reach for Flex when you need real flexbox control: justify="between" toolbars, wrapping chip rows, reversing order, direction that flips at a breakpoint, or per-child sizing via Flex.Item.

Purely presentational: it adds no role or keyboard behavior. Pick a semantic element with as (ul, nav, header, ...) when the group has meaning. Reverse directions change only the visual order, not the reading or tab order, so keep DOM order meaningful (WCAG 1.3.2, 2.4.3).

API reference

Flex

Flex props
PropTypeDefault
as

Element or component to render as. Native props follow the chosen element. Defaults to div.

ElementType—
direction

Main axis (flex-direction). Pass an object to change it at breakpoints, e.g. { base: "column", md: "row" }. Defaults to the browser default, row.

FlexResponsive<FlexDirection>—
wrap

Whether items wrap onto new lines (flex-wrap). Responsive. Defaults to nowrap: use wrap (or a responsive direction) for rows that must reflow at 320px (SC 1.4.10).

FlexResponsive<FlexWrap>—
align

Cross-axis alignment of items (align-items). Responsive. Defaults to stretch.

FlexResponsive<FlexAlign>—
justify

Main-axis distribution of items (justify-content). Responsive. Defaults to start.

FlexResponsive<FlexJustify>—
alignContent

Distribution of wrapped lines (align-content). Responsive. Only matters with wrap.

FlexResponsive<FlexAlignContent>—
gap

Gap between items on both axes, as a --space-* step. Responsive.

FlexResponsive<Space>—
rowGap

Gap between rows (lines), as a --space-* step. Overrides gap on that axis. Responsive.

FlexResponsive<Space>—
columnGap

Gap between columns (items in a row), as a --space-* step. Overrides gap on that axis. Responsive.

FlexResponsive<Space>—
inline

Render as inline-flex instead of flex.

boolean—
fullWidth

Stretch to the full width of the container.

boolean—
children

Flex items.

ReactNode—

Flex.Item

A child of Flex with its own sizing (grow, shrink, basis), order, and alignSelf. Only the properties you pass are applied, so an item with no props behaves like a plain child. Also available as Flex.Item.

Flex.Item props
PropTypeDefault
as

Element or component to render as. Native props follow the chosen element. Defaults to div.

ElementType—
grow

Share of free space to take (flex-grow). true means 1.

boolean | number—
shrink

Share of overflow to give up (flex-shrink). false means 0 (never shrink).

boolean | number—
basis

Starting size before growing or shrinking (flex-basis), e.g. "240px", "30%", "auto". Numbers are pixels.

string | number—
order

Visual order (order). Changes only the visual order, not reading or tab order.

number—
alignSelf

Cross-axis alignment for this item only (align-self), overriding the container's align.

"auto""start""center""end""stretch""baseline"—
children

Item content.

ReactNode—

See what changed in each version in the Changelog.

Accessibility report

Flex targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.

axe-core audit (live)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Dark mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.

Built-in behavior

Keyboard

Not focusable, so there's no keyboard interaction of its own.

Roles and states

Roles and states
ElementRoleStates and properties
<div>, or the element in asNative role of that element—

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck.2.1.1 (A), 2.1.2 (A)
FocusFocus moves in a logical order, is always visible, and isn't hidden behind sticky headers.2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA)
Screen readersNames, roles and states are announced correctly, and status changes are announced without moving focus.1.3.1 (A), 4.1.2 (A), 4.1.3 (AA)
ColorMeaning never depends on color alone; your own colors meet contrast in both modes.1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA)
Zoom and reflowAt 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed.1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA)
Pointer targetsClick and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap.2.5.8 (AA), 2.5.5 (AAA)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)