Playground

Flex

A flex container with direction, wrap, align, justify, gap and an inline form. Stack covers the common case.

  • Built on native elements
  • A plain element; adds no roles. Reversed directions change visual order only, so keep the source order meaningful.
  • Styles in one file: flex.css

Import

import '@monoline/css';
import {Flex} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add flex

Usage

import {Badge, Flex} from '@monoline/react';

<Flex justify="between" align="center" gap={3}>
  <Badge>left</Badge>
  <Badge>right</Badge>
</Flex>

Examples

Space between

Reversed column

Inline

Props

FlexProps

PropTypeDefaultDescription
direction"row" | "column" | "row-reverse" | "column-reverse"'row'Main axis: `row` (default), `column`, `row-reverse` or `column-reverse`.
wrapboolean–Lets children wrap onto new lines instead of shrinking. Default false.
align"center" | "start" | "end" | "stretch" | "baseline"–Cross-axis alignment (`align-items`): `start`, `center`, `end`, `stretch` or `baseline`.
justify"center" | "start" | "end" | "between" | "around"–Main-axis distribution (`justify-content`): `start`, `center`, `end`, `between` or `around`.
gap1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9–Step on the spacing scale: 1 = --s1 up to 9.
inlineboolean–`inline-flex` instead of `flex`.
asChildboolean–Render the child element (a `ul`, `nav`, `section`) with the flex styles instead of a `div`.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[data-align="baseline"]flex.css
[data-align="center"]flex.css
[data-align="end"]flex.css
[data-align="start"]flex.css
[data-align="stretch"]flex.css
[data-direction="column-reverse"]flex.css
[data-direction="column"]flex.css
[data-direction="row-reverse"]flex.css
[data-justify="around"]flex.css
[data-justify="between"]flex.css
[data-justify="center"]flex.css
[data-justify="end"]flex.css
[data-justify="start"]flex.css

CSS classes

ClassStylesheet
.flexflex.css
.flex-inlineflex.css
.flex-wrapflex.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.flex {
  border-color: var(--accent);
}
.flex[data-align="baseline"] {
  background: var(--wash);
}

Accessibility

  • A plain element; adds no roles. Reversed directions change visual order only, so keep the source order meaningful.