Allocation
<forma-allocation>
Distribute a bounded amount across multiple choices while preserving direct numeric entry.
- Authoring tag
<forma-allocation>- Category
- Assessment and survey
- Behavior owner
- Application / Limen
- Canonical source
patterns/allocation.html
Purpose
Allocation asks the user to split a fixed budget, such as 10 points or 100%, across several items. Each item is a labelled native number input, so values are typed directly and the browser enforces per-field min, max and step. The total row is an output in a polite live region. The aggregate rule (the sum must equal the budget) cannot be expressed in HTML, so the application calculates the total, writes it, and sets data-forma-state="invalid" when the rule is broken.
Use when
- Relative weight across items matters, not only their order.
- The budget is a small whole number or percentage that users can reason about.
- Direct, precise numeric entry is preferable to dragging.
Avoid when
- Only order matters: use Ranking.
- Each item is rated independently without a shared budget: use Single-choice matrix.
- A single number is requested: use Numeric stepper or Text field.
Behavior to know
- Native
input type="number"withinputmode="numeric"for each item. - Values are end-aligned with tabular numerals so columns of numbers line up.
- The total row is separated by a rule; the invalid state thickens the rule and uses the accent color, while the text states the problem.
- No sliders or drag are required.
Basic example
The smallest correct markup: the canonical pattern from patterns/allocation.html inside its public tag. Copy this first, then adapt labels, names and state.
Minimal allocation
Rendered from the canonical pattern file.
<forma-allocation class="forma-component-tag">
<fieldset class="forma-allocation">
<legend class="forma-allocation__legend">Distribute 10 points across these priorities.</legend>
<div class="forma-allocation__items">
<label class="forma-allocation__item">
<span>Reliability</span>
<input type="number" name="reliability" min="0" max="10" step="1" value="4" inputmode="numeric">
</label>
<label class="forma-allocation__item">
<span>Delivery speed</span>
<input type="number" name="delivery-speed" min="0" max="10" step="1" value="3" inputmode="numeric">
</label>
<label class="forma-allocation__item">
<span>Cost efficiency</span>
<input type="number" name="cost-efficiency" min="0" max="10" step="1" value="3" inputmode="numeric">
</label>
</div>
<div class="forma-allocation__total" data-forma-state="valid" aria-live="polite" aria-atomic="true">
<span>Total</span>
<output>10 / 10</output>
</div>
<p class="forma-field__description">Limen validates the aggregate total and renders the authoritative state.</p>
</fieldset>
</forma-allocation>
Click or tap the code once to select all of it, then copy.
Examples
Over-allocated total
The values add up to 12 of 10. The application marks the total invalid and writes a message saying how far over it is; per-field values are still individually valid.
<forma-allocation class="forma-component-tag">
<fieldset class="forma-allocation" aria-describedby="allocation-over-message">
<legend class="forma-allocation__legend">Distribute 10 points across these improvements.</legend>
<div class="forma-allocation__items">
<label class="forma-allocation__item"><span>Test coverage</span><input type="number" name="allocation-over-tests" min="0" max="10" step="1" value="5" inputmode="numeric"></label>
<label class="forma-allocation__item"><span>Documentation</span><input type="number" name="allocation-over-docs" min="0" max="10" step="1" value="4" inputmode="numeric"></label>
<label class="forma-allocation__item"><span>Build speed</span><input type="number" name="allocation-over-build" min="0" max="10" step="1" value="3" inputmode="numeric"></label>
</div>
<div class="forma-allocation__total" data-forma-state="invalid" aria-live="polite" aria-atomic="true">
<span>Total</span>
<output>12 / 10</output>
</div>
<p class="forma-validation-message" id="allocation-over-message">
<span class="forma-validation-message__mark" aria-hidden="true">!</span>
Remove 2 points so the total is exactly 10.
</p>
</fieldset>
</forma-allocation>
Click or tap the code once to select all of it, then copy.
Percentage split in progress
A 100% budget with one item still at zero. The total shows what remains; the state is not invalid until the user tries to continue, which is an application decision.
<forma-allocation class="forma-component-tag">
<fieldset class="forma-allocation">
<legend class="forma-allocation__legend">How is your team's time split across work types?</legend>
<p class="forma-field__description">Enter whole percentages. The total must reach 100%.</p>
<div class="forma-allocation__items">
<label class="forma-allocation__item"><span>New features</span><input type="number" name="allocation-percent-features" min="0" max="100" step="5" value="50" inputmode="numeric"></label>
<label class="forma-allocation__item"><span>Maintenance and upgrades</span><input type="number" name="allocation-percent-maintenance" min="0" max="100" step="5" value="30" inputmode="numeric"></label>
<label class="forma-allocation__item"><span>Unplanned incidents and support requests</span><input type="number" name="allocation-percent-incidents" min="0" max="100" step="5" value="0" inputmode="numeric"></label>
</div>
<div class="forma-allocation__total" data-forma-state="valid" aria-live="polite" aria-atomic="true">
<span>Total</span>
<output>80% (20% remaining)</output>
</div>
</fieldset>
</forma-allocation>
Click or tap the code once to select all of it, then copy.
Mobile
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.
Allocation on a phone
Below 44rem each item's label sits above a full-width number field, which is easier to tap and type into.
What changes at narrow widths
- Each item switches from a label/field row to a single column: label on top, input full width underneath.
- Number inputs keep a 44px minimum height and
inputmode="numeric"brings up a numeric keypad on touch devices. - The total row wraps its label and value if space runs out; values stay in tabular numerals.
- Long item labels wrap; nothing scrolls horizontally at 320px.
<forma-allocation class="forma-component-tag">
<fieldset class="forma-allocation">
<legend class="forma-allocation__legend">Split 10 points between these perks.</legend>
<div class="forma-allocation__items">
<label class="forma-allocation__item"><span>Learning budget</span><input type="number" name="allocation-mobile-learning" min="0" max="10" step="1" value="6" inputmode="numeric"></label>
<label class="forma-allocation__item"><span>Home office equipment</span><input type="number" name="allocation-mobile-office" min="0" max="10" step="1" value="4" inputmode="numeric"></label>
</div>
<div class="forma-allocation__total" data-forma-state="valid" aria-live="polite" aria-atomic="true">
<span>Total</span>
<output>10 / 10</output>
</div>
</fieldset>
</forma-allocation>
Click or tap the code once to select all of it, then copy.
Mobile · 320px
The canonical pattern in a true 320px viewport, the minimum width every Forma component must support without page-level horizontal scrolling.
API and configuration
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 |
|---|---|---|---|---|
type | input | number | — | Required. Direct numeric entry is the baseline interaction. |
name | input | string | — | Field name for each item's value. |
min | input | number | — | Native lower bound for one item. It cannot express the aggregate total. |
max | input | number | — | Native upper bound for one item, usually the whole budget. |
step | input | number | "1" | Native granularity; arrow keys step by this amount. |
value | input | number | — | Initial or saved value for the item. |
inputmode | input | numeric | — | Requests a numeric keypad on touch devices. |
aria-live | .forma-allocation__total | polite | — | Announces total updates written by the application. |
aria-atomic | .forma-allocation__total | true | — | Reads label and value together. |
aria-describedby | fieldset | id list | — | Associates the total error message with the group. |
| Hook | Kind | Values or default | Description |
|---|---|---|---|
.forma-allocation | Block class | — | Root fieldset with browser border and padding removed. |
.forma-allocation__item | Element class | — | Label wrapping item text and its number input; a two-column row on wide screens, stacked below 44rem. |
.forma-allocation__items | Element class | — | Grid stacking the items. |
.forma-allocation__legend | Element class | — | Instruction stating the budget. |
.forma-allocation__total | Element class | — | Total row above a rule, holding an output element in tabular numerals. |
[data-forma-state] | Attribute hook | "invalid" | Set by the application on .forma-allocation__total. invalid thickens the rule and switches to the accent color; other values (such as valid) use the default presentation. |
| Keys | Result |
|---|---|
| Tab / Shift+Tab | Moves between the number fields. |
| Arrow Up / Arrow Down | Native number input stepping by step, clamped to min and max. |
| Digits | Direct entry of a value. |
| Event | Description |
|---|---|
input / change | Native events from each number input. Limen recalculates the total on input and validates on change or submit. |
Form behavior
Each input submits its own name=value and participates in native range and step validation. The aggregate total is not validated natively; the application must block submission when it is wrong.
States
| State | How it is expressed | Presentation |
|---|---|---|
| Valid total | data-forma-state="valid" (or absent) | Default total row with a 1px rule. |
| Invalid total | data-forma-state="invalid" | 2px rule and accent-colored text; pair with a text message that says how to fix it. |
| Field out of range | native :invalid from min/max/step | The browser reports the field error on submit; Forma adds no extra styling. |
| Focus | :focus-visible on an input | Foundation two-tone focus ring on the field. |
Accessibility
Forma provides
- Wraps each input in its label so every field has an accessible name.
- Keeps numeric entry as the primary interaction with 44px fields.
- Styles the total as a live, atomic region and does not rely on color for the invalid state (the rule weight also changes).
Your application supplies
- Calculate and write the total, including remaining or excess amounts in words.
- Set data-forma-state and render a Validation message that says exactly what to change.
- Block progression while the total is wrong and move focus to the message or a Validation summary.
Responsive behavior
- Wide: item rows are
minmax(0, 1fr) minmax(5rem, 7rem)so numbers align in one column. - Below 44rem: each item stacks label over a full-width input.
- The total row is a wrapping flex row.
Motion
- No animation: the total and its state change immediately when the application writes them.
Usage guidance
Do
- State the budget in the legend and keep it a round number.
- Show remaining or excess amounts in the total text.
Avoid
- Requiring sliders or drag to allocate.
- Auto-adjusting other fields when one changes; users lose track of what they entered.
Verification specimens
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.