Primary content
Stack owns only the vertical relationship between independent children.
<forma-stack>
Applies consistent vertical rhythm between semantic siblings.
<forma-stack>patterns/stack.htmlA stack is the smallest composition primitive: it places independent children in one vertical column and owns only the space between them. Children keep their own semantics and internal spacing; the stack removes their block margins and inserts a single, predictable relationship instead. Use it inside forms, panels, cards and page regions whenever siblings should read as one ordered group. The data-density posture changes the gap for a whole region without touching the markup of its children.
The smallest correct markup: the canonical pattern from patterns/stack.html inside its public tag. Copy this first, then adapt labels, names and state.
Rendered from the canonical pattern file.
Static specimen. Its buttons stand for application actions that the consuming application implements; this script-free documentation does not perform them. Its controls are shown for their markup and appearance and cannot be operated here.
Supporting context remains grouped with the heading.
Stack owns only the vertical relationship between independent children.
<forma-stack class="forma-component-tag">
<section class="forma-stack" aria-label="Stack composition">
<header><h2>Section title</h2><p>Supporting context remains grouped with the heading.</p></header>
<article><h3>Primary content</h3><p>Stack owns only the vertical relationship between independent children.</p></article>
<footer><button type="button">Continue</button></footer>
</section>
</forma-stack>
Click or tap the code once to select all of it, then copy.
A stack arranges a heading, two switches and a save action inside a surface. The stack owns the vertical relationship; each switch keeps its own internal layout.
Live demo. 2 native actions work here and are verified by an outcome test.
Choose which events send you an email. Changes apply to this workspace only.
<forma-stack class="forma-component-tag">
<section class="forma-surface forma-stack" aria-labelledby="stack-settings-panel-title">
<h2 id="stack-settings-panel-title">Workspace notifications</h2>
<p>Choose which events send you an email. Changes apply to this workspace only.</p>
<label class="forma-switch">
<input class="forma-switch__input" type="checkbox" role="switch" name="stack-settings-panel-builds" value="on" checked>
<span class="forma-switch__track" aria-hidden="true"></span>
<span class="forma-switch__text"><span class="forma-switch__label">Failed builds</span></span>
</label>
<label class="forma-switch">
<input class="forma-switch__input" type="checkbox" role="switch" name="stack-settings-panel-mentions" value="on">
<span class="forma-switch__track" aria-hidden="true"></span>
<span class="forma-switch__text"><span class="forma-switch__label">Mentions in review comments</span></span>
</label>
</section>
</forma-stack>
Click or tap the code once to select all of it, then copy.
The same kind of content under data-density="compact". The posture reduces the stack gap so more fields fit on screen for repeated data entry; field order, labels and target sizes do not change.
Static specimen. Submitting or resetting it needs the consuming application's form handling, which this documentation does not have. Its controls are shown for their markup and appearance and cannot be operated here.
<forma-stack class="forma-component-tag">
<form class="forma-stack" data-density="compact" aria-labelledby="stack-compact-density-title">
<h2 id="stack-compact-density-title">Shipment details</h2>
<div class="forma-field">
<label class="forma-field__label" for="stack-compact-density-reference">Reference</label>
<input id="stack-compact-density-reference" name="reference" type="text" autocomplete="off">
</div>
<div class="forma-field">
<label class="forma-field__label" for="stack-compact-density-carrier">Carrier</label>
<input id="stack-compact-density-carrier" name="carrier" type="text">
</div>
<div class="forma-field">
<label class="forma-field__label" for="stack-compact-density-weight">Weight (kg)</label>
<input id="stack-compact-density-weight" name="weight" type="number" inputmode="decimal" min="0" step="0.1">
</div>
<div class="forma-cluster">
<button type="submit">Save shipment</button>
<button type="reset">Clear</button>
</div>
</form>
</forma-stack>
Click or tap the code once to select all of it, then copy.
An outer relaxed stack separates two groups; each group is its own tighter stack. Proximity, not borders, tells the reader which heading owns which list.
Freeze the main branch and confirm the migration plan with the database owner.
Run the full regression suite against staging.
Watch error rates for one hour and post the summary in the release channel.
<forma-stack class="forma-component-tag">
<article class="forma-stack" data-density="relaxed" aria-labelledby="stack-nested-grouping-title">
<h2 id="stack-nested-grouping-title">Release 4.2 checklist</h2>
<section class="forma-stack" data-density="compact" aria-labelledby="stack-nested-grouping-before">
<h3 id="stack-nested-grouping-before">Before the release</h3>
<p>Freeze the main branch and confirm the migration plan with the database owner.</p>
<p>Run the full regression suite against staging.</p>
</section>
<section class="forma-stack" data-density="compact" aria-labelledby="stack-nested-grouping-after">
<h3 id="stack-nested-grouping-after">After the release</h3>
<p>Watch error rates for one hour and post the summary in the release channel.</p>
</section>
</article>
</forma-stack>
Click or tap the code once to select all of it, then copy.
Each mobile example renders in its own document inside a real narrow viewport, so Forma's media and container queries run exactly as they would on a phone. Choose a width to compare.
A phone-width account summary. The stack is already a single column, so nothing recomposes; long values wrap inside each child.
Live demo. 1 native action works here and is verified by an outcome test.
<forma-stack class="forma-component-tag">
<section class="forma-stack" aria-labelledby="stack-mobile-account-summary-title">
<h2 id="stack-mobile-account-summary-title">Account</h2>
<dl class="forma-key-value-list">
<div><dt>Owner</dt><dd>Priya Raman</dd></div>
<div><dt>Billing email</dt><dd>accounts-payable.northwind-logistics@example.com</dd></div>
<div><dt>Plan</dt><dd>Team, billed annually</dd></div>
</dl>
<p>Invoices are issued on the first business day of each month.</p>
<a href="#stack-mobile-account-summary-title">Manage billing</a>
</section>
</forma-stack>
Click or tap the code once to select all of it, then copy.
The canonical pattern in a true 320px viewport, the minimum width every Forma component must support without page-level horizontal scrolling.
Static specimen. Its buttons stand for application actions that the consuming application implements; this script-free documentation does not perform them. Its controls are shown for their markup and appearance and cannot be operated here.
Forma components have no JavaScript API. Their public contract is the markup: native elements and attributes you write, and the CSS hooks below. The CSS hook table is generated from the built stylesheet, so it always matches the shipped implementation.
| Attribute | On | Values | Default | Description |
|---|---|---|---|---|
data-density | .forma-stack | relaxed | standard | compact | analytical | absent (1rem gap) | Contextual density posture. Sets the stack gap to 1.5rem (relaxed), 1rem (standard) or 0.5rem (compact, analytical). It is not a data-forma-* hook and never changes semantics, order or target size. |
aria-labelledby | section / article / form | id of the group heading | — | Names a stacked region when the element is a landmark or a named group. The stack itself adds no role. |
| Hook | Kind | Values or default | Description |
|---|---|---|---|
.forma-stack | Block class | — | Vertical flex column. Removes block margins from direct children and spaces them with a gap plus a leading margin on every child after the first. |
[data-density] | Attribute hook | — | Density posture on the stack element. relaxed = 1.5rem, standard = 1rem, compact and analytical = 0.5rem gap (spacing primitives, so skins rescale them). |
--forma-stack-gap | Custom property | — | Foundation-layer gap between children. Default --forma-primitive-spacing-4 (1rem). Ignored when data-density is set. |
--forma-stack-space | Custom property | default var(--forma-primitive-spacing-4, 1rem) | Component-layer margin inserted before each child after the first. Default --forma-primitive-spacing-4 (1rem). It adds to the gap, so the visible space between children is gap plus this value. |
| Keys | Result |
|---|---|
| Tab / Shift+Tab | Moves through focusable children in source order, which is also the visual order. |
Not a form control. A form or fieldset may itself be the stack; submission is unaffected.
| State | How it is expressed | Presentation |
|---|---|---|
| Default rhythm | no data-density | Gap from --forma-stack-gap plus the leading margin from --forma-stack-space. |
| Density posture | data-density="relaxed | standard | compact | analytical" | Replaces the gap with the posture's spacing. The leading margin still applies. |
data-density when the context changes.section class="forma-stack") instead of adding a wrapper div.ul or ol and make that element the stack.Generated fault-injection specimens expose content, spacing, color-cue, and reduced-effective-contrast risks. They screen presentation robustness as engineering screens without claiming human-subject validation.