Basic Alignment
Add nds-flex to any element to turn it into a flex container with sensible defaults. Override --justify, --align, and --gap inline to tune the layout.
<div class="nds-flex" style="--justify: flex-start;">
<span class="nds-tag nds-sm"><span class="nds-label">First</span></span>
<span class="nds-tag nds-sm"><span class="nds-label">Second</span></span>
<span class="nds-tag nds-sm"><span class="nds-label">Third</span></span>
</div>
Direction Control
Add nds-row or nds-col to flip the main axis. Combine with nds-reverse to invert child order for layout or RTL action-flip patterns.
<div class="nds-flex nds-row" style="--gap: var(--spacing-md);">
<button class="nds-btn nds-primary nds-sm">
<span class="nds-label">Accept</span>
</button>
<button class="nds-btn nds-secondary-outline nds-sm">
<span class="nds-label">Review</span>
</button>
<button class="nds-btn nds-subtle nds-sm">
<span class="nds-label">Dismiss</span>
</button>
</div>
Wrapping
Add nds-wrap to let children flow onto multiple lines when the container is too narrow. Use nds-nowrap to force a single line even when content overflows.
<div class="nds-flex nds-wrap" style="--gap: var(--spacing-sm);">
<span class="nds-tag nds-sm"><span class="nds-label">Government</span></span>
<span class="nds-tag nds-sm"><span class="nds-label">Digital Transformation</span></span>
<span class="nds-tag nds-sm"><span class="nds-label">Accessibility</span></span>
<span class="nds-tag nds-sm"><span class="nds-label">Design System</span></span>
<span class="nds-tag nds-sm"><span class="nds-label">Standards</span></span>
<span class="nds-tag nds-sm"><span class="nds-label">Services</span></span>
<span class="nds-tag nds-sm"><span class="nds-label">Compliance</span></span>
<span class="nds-tag nds-sm"><span class="nds-label">Open Data</span></span>
</div>
Built-in Features
Works with a single class and zero JavaScript. No initialization, no event listeners, no cleanup.
Items align to center cross-axis, start along the main axis, and separate by --spacing-xl gap out of the box.
Override --justify, --align, and --gap inline or in a parent style without writing a single new class.
nds-row and nds-col flip direction on any flex element, including components that declare their own display: flex like card actions.
Pair nds-reverse with a direction class to flip visual child order, useful for RTL-specific action arrangements.
nds-wrap enables multi-line flow; nds-nowrap forces a single line. Combine with child min-width for container-responsive stacking.
Usage Guidelines
Best Practices
- Use
nds-flexfor quick one-off alignment or direction fixes on ad-hoc elements where a component does not already handle the layout - Use Grid instead for page-level or section-level layout composition. Grid handles responsive column counts and gap halving in a single rule through its tier-based custom properties
- Use
nds-rowornds-colstandalone (withoutnds-flex) when the parent already declaresdisplay: flexin its own component SCSS, such as thends-card-actions nds-rowaction-flip pattern - Override defaults with inline
--justify,--align, and--gapCSS variables rather than extending the utility with new modifier classes. This keeps the CSS output small and the API predictable - For container-responsive stacking (items stack when the container gets narrow, not when the viewport changes), add
nds-wrapwith amin-widthon children. More resilient than breakpoint-based direction swaps - Do not add
nds-flexto elements inside components that already ship their own flex logic (cards, forms, main navigation). The component handles alignment more precisely than a generic utility - Do not use
nds-flexfor multi-breakpoint layout composition. If you need a row that becomes a column on mobile, use Grid with--max-col: 2; --min-col: 1;instead. Flex direction swaps rarely come alone and usually trigger other responsive adjustments - Keep the
width: 100%default in mind. When the flex container must only occupy its content's width, wrap it in an inline-level parent or override with inlinewidth: auto
Modifier Classes
| Class | Description |
|---|---|
nds-flex | Declares the element as a flex container with default gap, center cross-axis alignment, and start main-axis alignment |
nds-row | Sets flex-direction: row. Unscoped: works with or without nds-flex on the same element |
nds-col | Sets flex-direction: column. Unscoped: works with or without nds-flex on the same element |
nds-reverse | Combined with nds-row or nds-col, reverses visual child order (row-reverse or column-reverse) |
nds-wrap | Enables flex-wrap: wrap so children flow onto multiple lines when the container is too narrow |
nds-nowrap | Forces flex-wrap: nowrap so children stay on one line, potentially overflowing |
CSS Custom Properties
| Property | Default | Description |
|---|---|---|
--justify | flex-start | Value for justify-content. Accepts any valid CSS keyword such as center, flex-end, space-between |
--align | center | Value for align-items. Accepts keywords such as start, end, stretch, baseline |
--gap | var(--spacing-xl) | Gap between children. Accepts any CSS length or spacing token such as var(--spacing-md) or 0 |