Stack

A one-dimensional flex layout: children in a column or a row, spaced by a gap from the --mrd-space-* scale. Use it instead of margins between siblings.

StableSource
1
2
3

Import

tsx
import { Stack } from "@merid/react";

Examples

Row

1
2
3

Alignment

align maps to align-items, justify to justify-content (between is space-between).

short
tall
mid

Wrapping

Design
Tokens
React
CSS
Accessibility
Dark mode

Semantic element

Use as to render a list, nav or form — the layout stays the same.

  • First item
  • Second item

API reference

Renders a div unless as is given; forwards its ref and passes all HTML attributes through.

PropTypeDefaultDescription
direction"row" | "column""column"Main axis.
gap0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 14 | 16 | 18 | 284Gap from the --mrd-space-* scale (4 = 16px).
align"start" | "center" | "end" | "stretch" | "baseline"–Cross-axis alignment (align-items).
justify"start" | "center" | "end" | "between"–Main-axis distribution (justify-content).
wrapbooleanfalseAllows items to wrap onto multiple lines.
asElementType"div"Element or component to render instead of a div.

Styling

HookValues
.mrd-stackRoot element
data-directionrow · column
data-alignstart · center · end · stretch · baseline
data-justifystart · center · end · between
data-wrapPresent when wrap

Component variable: --mrd-stack-gap, set inline from gap. Override it in CSS for responsive gaps:

css
@media (max-width: 640px) {
  .actions.mrd-stack { --mrd-stack-gap: var(--mrd-space-2); }
}

Accessibility

  • Stack is layout only and adds no role. Choose the right element with as (ul, nav, form).
  • Visual order follows DOM order; don't reverse it with CSS, or focus order and reading order will disagree.

Guidelines

Do

Use one gap per stack and nest stacks for different rhythms.

Avoid

Mix gap with margins on children to fine-tune spacing.

  • Grid — two-dimensional layout.
  • Container — caps content width.