Assessment and survey

Allocation

<forma-allocation>

Distribute a bounded amount across multiple choices while preserving direct numeric entry.

Authoring tag
<forma-allocation>
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

Behavior to know

  • Native input type="number" with inputmode="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.

Canonical

Minimal allocation

Rendered from the canonical pattern file.

Distribute 10 points across these priorities.
Total 10 / 10

Limen validates the aggregate total and renders the authoritative state.

HTML · Minimal allocation Raw HTML for HTML · Minimal allocation
<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

Scenario

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.

Distribute 10 points across these improvements.
Total 12 / 10

Remove 2 points so the total is exactly 10.

HTML · Over-allocated total Raw HTML for HTML · Over-allocated total
<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.

Scenario

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.

How is your team's time split across work types?

Enter whole percentages. The total must reach 100%.

Total 80% (20% remaining)
HTML · Percentage split in progress Raw HTML for HTML · Percentage split in progress
<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.

Mobile example

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.

Viewport width

Frames narrower than the selected width show the component at the width available.

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.
HTML · Allocation on a phone Raw HTML for HTML · Allocation on a phone
<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.

Baseline

Mobile · 320px

The canonical pattern in a true 320px viewport, the minimum width every Forma component must support without page-level horizontal scrolling.

Viewport width

Frames narrower than the selected width show the component at the width available.

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.

Native and ARIA attributes
AttributeOnValuesDefaultDescription
typeinputnumber—Required. Direct numeric entry is the baseline interaction.
nameinputstring—Field name for each item's value.
mininputnumber—Native lower bound for one item. It cannot express the aggregate total.
maxinputnumber—Native upper bound for one item, usually the whole budget.
stepinputnumber"1"Native granularity; arrow keys step by this amount.
valueinputnumber—Initial or saved value for the item.
inputmodeinputnumeric—Requests a numeric keypad on touch devices.
aria-live.forma-allocation__totalpolite—Announces total updates written by the application.
aria-atomic.forma-allocation__totaltrue—Reads label and value together.
aria-describedbyfieldsetid list—Associates the total error message with the group.
CSS hooks (derived from dist/all.css)
HookKindValues or defaultDescription
.forma-allocationBlock class—Root fieldset with browser border and padding removed.
.forma-allocation__itemElement class—Label wrapping item text and its number input; a two-column row on wide screens, stacked below 44rem.
.forma-allocation__itemsElement class—Grid stacking the items.
.forma-allocation__legendElement class—Instruction stating the budget.
.forma-allocation__totalElement 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.
Keyboard interaction
KeysResult
Tab / Shift+TabMoves between the number fields.
Arrow Up / Arrow DownNative number input stepping by step, clamped to min and max.
DigitsDirect entry of a value.
Events
EventDescription
input / changeNative 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

Allocation states
StateHow it is expressedPresentation
Valid totaldata-forma-state="valid" (or absent)Default total row with a 1px rule.
Invalid totaldata-forma-state="invalid"2px rule and accent-colored text; pair with a text message that says how to fix it.
Field out of rangenative :invalid from min/max/stepThe browser reports the field error on submit; Forma adds no extra styling.
Focus:focus-visible on an inputFoundation 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.