Form inputs

Rule builder

<forma-rule-builder>

Field/operator/value clauses for typed rule editing while the application owns expression semantics.

Authoring tag
<forma-rule-builder>
Category
Form inputs
Behavior owner
Application / Limen
Canonical source
patterns/rule-builder.html

Purpose

A rule builder lets users compose a condition from clauses, each a field, an operator and a value, combined in AND/OR groups, with a plain-language summary of what the rule means. Forma provides the visual contract: a bordered panel with a header, groups with a visible operator badge, clause rows laid out as a grid of labelled native selects or inputs, and a summary bar. Adding and removing clauses, which operators and values a field allows, validation, the expression model and its serialization all belong to the application (Limen/Ordo); Forma never interprets the rule.

Use when

  • Users define when something applies (show a question, route a ticket, include a record) with conditions over typed fields.
  • Conditions combine with AND/OR and users need to read the result back in plain language.
  • Each clause can be edited with ordinary form controls.

Avoid when

Behavior to know

  • Each clause is three labelled controls and a remove button in one row that stacks at narrow widths.
  • Group logic is shown as text (AND, OR) in a badge, not by color or indentation alone.
  • The summary restates the rule in words so users can check it without parsing the clauses.

Basic example

The smallest correct markup: the canonical pattern from patterns/rule-builder.html inside its public tag. Copy this first, then adapt labels, names and state.

Canonical

Minimal rule builder

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.

Applicability rule

Define when this section is shown.

AND

Meaning: Show this section when Answer(Q1) = Yes.

HTML · Minimal rule builder Raw HTML for HTML · Minimal rule builder
<forma-rule-builder class="forma-component-tag">
<section class="forma-rule-builder" aria-labelledby="rule-builder-title">
  <header class="forma-rule-builder__header">
    <div>
      <h2 id="rule-builder-title">Applicability rule</h2>
      <p>Define when this section is shown.</p>
    </div>
    <button type="button">Add condition</button>
  </header>

  <div class="forma-rule-group" data-forma-operator="and">
    <div class="forma-rule-group__operator" aria-label="All conditions must be true">AND</div>

    <div class="forma-rule-clause">
      <label>
        <span>Field</span>
        <select>
          <option>Answer: Q1</option>
        </select>
      </label>
      <label>
        <span>Operator</span>
        <select>
          <option>is equal to</option>
        </select>
      </label>
      <label>
        <span>Value</span>
        <select>
          <option>Yes</option>
        </select>
      </label>
      <button type="button" aria-label="Remove condition">Remove</button>
    </div>
  </div>

  <p class="forma-rule-builder__summary"><strong>Meaning:</strong> Show this section when Answer(Q1) = Yes.</p>
</section>
</forma-rule-builder>

Click or tap the code once to select all of it, then copy.

Examples

Scenario

Routing rule with a nested OR group

An AND group containing one clause and a nested OR group of two clauses. Each group is a named role=group, the visible operator badge is hidden from assistive technology because the group name says the same thing, and remove buttons name their clause.

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.

Escalation routing

Tickets that match go to the priority queue.

Meaning: Route to the priority queue when the plan is Enterprise and either severity is Critical or the ticket has been open more than 4 hours.

HTML · Routing rule with a nested OR group Raw HTML for HTML · Routing rule with a nested OR group
<forma-rule-builder class="forma-component-tag">
  <section class="forma-rule-builder" aria-labelledby="rule-builder-nested-title">
    <header class="forma-rule-builder__header">
      <div>
        <h2 id="rule-builder-nested-title">Escalation routing</h2>
        <p>Tickets that match go to the priority queue.</p>
      </div>
      <button type="button">Add condition</button>
    </header>
    <div class="forma-rule-group" data-forma-operator="and" role="group" aria-label="All of these conditions (AND)">
      <p class="forma-rule-group__operator" aria-hidden="true">AND</p>
      <div class="forma-rule-clause">
        <label><span>Field</span>
          <select name="rule-1-field"><option selected>Customer plan</option><option>Region</option><option>Severity</option></select>
        </label>
        <label><span>Operator</span>
          <select name="rule-1-operator"><option selected>is</option><option>is not</option></select>
        </label>
        <label><span>Value</span>
          <select name="rule-1-value"><option selected>Enterprise</option><option>Business</option></select>
        </label>
        <button type="button" aria-label="Remove condition: Customer plan is Enterprise">Remove</button>
      </div>
      <div class="forma-rule-group" data-forma-operator="or" role="group" aria-label="Any of these conditions (OR)">
        <p class="forma-rule-group__operator" aria-hidden="true">OR</p>
        <div class="forma-rule-clause">
          <label><span>Field</span>
            <select name="rule-2-field"><option>Customer plan</option><option>Region</option><option selected>Severity</option></select>
          </label>
          <label><span>Operator</span>
            <select name="rule-2-operator"><option selected>is</option><option>is not</option></select>
          </label>
          <label><span>Value</span>
            <select name="rule-2-value"><option selected>Critical</option><option>High</option></select>
          </label>
          <button type="button" aria-label="Remove condition: Severity is Critical">Remove</button>
        </div>
        <div class="forma-rule-clause">
          <label><span>Field</span>
            <select name="rule-3-field"><option>Customer plan</option><option>Region</option><option selected>Open hours</option></select>
          </label>
          <label><span>Operator</span>
            <select name="rule-3-operator"><option selected>more than</option><option>less than</option></select>
          </label>
          <label><span>Value</span>
            <input type="number" name="rule-3-value" min="0" value="4" inputmode="numeric">
          </label>
          <button type="button" aria-label="Remove condition: Open hours more than 4">Remove</button>
        </div>
      </div>
    </div>
    <p class="forma-rule-builder__summary"><strong>Meaning:</strong> Route to the priority queue when the plan is Enterprise and either severity is Critical or the ticket has been open more than 4 hours.</p>
  </section>
</forma-rule-builder>

Click or tap the code once to select all of it, then copy.

Scenario

Incomplete condition

The application rejected a clause with no value chosen. The empty value select is marked invalid and linked to a validation message; the summary says the rule cannot be applied yet instead of guessing its meaning.

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.

Section visibility

Show the follow-up section only to some respondents.

Choose a value for this condition.

Meaning: Incomplete. The rule will not be applied until every condition has a value.

HTML · Incomplete condition Raw HTML for HTML · Incomplete condition
<forma-rule-builder class="forma-component-tag">
  <section class="forma-rule-builder" aria-labelledby="rule-builder-incomplete-title">
    <header class="forma-rule-builder__header">
      <div>
        <h2 id="rule-builder-incomplete-title">Section visibility</h2>
        <p>Show the follow-up section only to some respondents.</p>
      </div>
      <button type="button">Add condition</button>
    </header>
    <div class="forma-rule-group" data-forma-operator="and" role="group" aria-label="All of these conditions (AND)">
      <p class="forma-rule-group__operator" aria-hidden="true">AND</p>
      <div class="forma-rule-clause">
        <label><span>Field</span>
          <select name="visibility-field"><option selected>Answer: Q4 Team size</option></select>
        </label>
        <label><span>Operator</span>
          <select name="visibility-operator"><option selected>is at least</option></select>
        </label>
        <label><span>Value</span>
          <select name="visibility-value" aria-invalid="true" aria-describedby="rule-builder-incomplete-error"><option value="" selected>Choose a value</option><option>10</option><option>50</option></select>
        </label>
        <button type="button" aria-label="Remove condition: Q4 Team size">Remove</button>
      </div>
      <p class="forma-validation-message" id="rule-builder-incomplete-error">
        <span class="forma-validation-message__mark" aria-hidden="true">!</span>
        Choose a value for this condition.
      </p>
    </div>
    <p class="forma-rule-builder__summary"><strong>Meaning:</strong> Incomplete. The rule will not be applied until every condition has a value.</p>
  </section>
</forma-rule-builder>

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

Mobile audience rule

A two-clause AND rule at phone width. The header and each clause stack so every control gets the full width.

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.

Viewport width

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

What changes at narrow widths

  • At 44rem (704px) and below each clause becomes one column: Field, Operator, Value and Remove stack in source order.
  • The header stacks too, so Add condition moves below the title and stretches to the panel width.
  • Every select and button keeps a 44px minimum height for touch.
  • The summary wraps inside its bar; nothing scrolls horizontally.
HTML · Mobile audience rule Raw HTML for HTML · Mobile audience rule
<forma-rule-builder class="forma-component-tag">
  <section class="forma-rule-builder" aria-labelledby="rule-builder-mobile-title">
    <header class="forma-rule-builder__header">
      <div>
        <h2 id="rule-builder-mobile-title">Campaign audience</h2>
        <p>Who receives this announcement.</p>
      </div>
      <button type="button">Add condition</button>
    </header>
    <div class="forma-rule-group" data-forma-operator="and" role="group" aria-label="All of these conditions (AND)">
      <p class="forma-rule-group__operator" aria-hidden="true">AND</p>
      <div class="forma-rule-clause">
        <label><span>Field</span>
          <select name="audience-1-field"><option selected>Role</option></select>
        </label>
        <label><span>Operator</span>
          <select name="audience-1-operator"><option selected>is</option></select>
        </label>
        <label><span>Value</span>
          <select name="audience-1-value"><option selected>Administrator</option></select>
        </label>
        <button type="button" aria-label="Remove condition: Role is Administrator">Remove</button>
      </div>
      <div class="forma-rule-clause">
        <label><span>Field</span>
          <select name="audience-2-field"><option selected>Last sign-in</option></select>
        </label>
        <label><span>Operator</span>
          <select name="audience-2-operator"><option selected>within</option></select>
        </label>
        <label><span>Value</span>
          <select name="audience-2-value"><option selected>30 days</option></select>
        </label>
        <button type="button" aria-label="Remove condition: Last sign-in within 30 days">Remove</button>
      </div>
    </div>
    <p class="forma-rule-builder__summary"><strong>Meaning:</strong> Administrators who signed in within the last 30 days.</p>
  </section>
</forma-rule-builder>

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.

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.

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
aria-labelledbysection.forma-rule-builderid of the heading—Names the rule builder region with its visible heading.
data-forma-operator.forma-rule-groupand | or—Application-owned record of the group's logic, used by the pattern. Forma does not style it; the operator badge text is what users see.
role.forma-rule-groupgroup—Exposes the group and its accessible name to assistive technology.
aria-label.forma-rule-group / remove buttonstring—Names each group by its logic and each Remove button by its clause; keep the visible word Remove in the name.
aria-hidden.forma-rule-group__operatortrue—Hides the visual badge when the group's aria-label already states the logic.
aria-invalidclause controltrueabsentSet by the application on an incomplete or invalid clause control.
aria-describedbyclause controlid of the validation message—Links the clause error to the control.
CSS hooks (derived from dist/all.css)
HookKindValues or defaultDescription
.forma-rule-builderBlock class—Root panel with a functional border on the primary surface.
.forma-rule-builder__headerElement class—Header row with title and description on one side and actions on the other; stacks at 44rem and below.
.forma-rule-builder__summaryElement class—Plain-language meaning bar on the secondary surface at the bottom of the panel.
.forma-rule-clauseBlock class—Four-column grid (field, operator, value, remove) with bottom-aligned controls; one column at 44rem and below. Direct labels become small label-over-control grids.
.forma-rule-groupBlock class—Padded grid of an operator badge and its clauses or nested groups.
.forma-rule-group__operatorElement class—Monospace uppercase badge naming the group logic (AND, OR).
Keyboard interaction
KeysResult
Tab / Shift+TabMoves through the header action, each clause's controls and Remove buttons in source order.
Native control keysSelects and inputs keep their native keyboard behavior.
ApplicationAfter Add or Remove, the application must move focus to the new clause's first control or to a sensible neighbor; Forma provides no focus management.
Events
EventDescription
change / clickNative events from clause controls and buttons. Building, validating and serializing the expression is application code; Forma adds no events.

Form behavior

Clause controls are ordinary form controls and submit individually if inside a form. The structured expression is assembled and serialized by the application.

States

Rule builder states
StateHow it is expressedPresentation
Completeevery clause has values; summary states the meaningThe summary restates the rule in words.
Incomplete / invalidaria-invalid on a clause control plus a linked .forma-validation-messageError text with a non-color mark in the group; the summary says the rule cannot apply yet.
Nested group.forma-rule-group inside .forma-rule-groupInner group gets its own operator badge and padding; use nesting only when the logic requires it.
Focus:focus-visibleFoundation focus ring on the focused control.

Accessibility

Forma provides

  • Every clause control is wrapped in a visible label.
  • Group logic is displayed as text, and the panel border maps to CanvasText in forced-colors mode.
  • Clauses stack at narrow widths so controls never shrink below a usable size.

Your application supplies

  • Give each group role="group" with a name stating its logic; the canonical pattern's aria-label on a plain div is not reliably exposed.
  • Give each Remove button a name that identifies its clause.
  • Manage focus after adding or removing clauses and announce the change.
  • Keep the summary accurate; it is the most readable view of the rule for everyone.

Responsive behavior

  • Above 44rem clause columns are minmax(8rem, …), so very narrow containers may need the stacked layout sooner than the breakpoint.
  • At 44rem (704px) and below the header and clauses become single columns.
  • The root has min-inline-size: 0, so it shrinks inside grid and flex parents; the summary wraps.

Motion

  • No animation: clauses and groups appear and disappear without transitions. Buttons use the shared hover and press background interpolation.

Usage guidance

Do

  • Show the plain-language meaning and update it with every change.
  • Offer only operators and values that make sense for the chosen field.

Avoid

  • Deep nesting; flatten logic where possible.
  • Encoding AND/OR only with color or indentation.
  • Putting expression semantics in CSS classes; keep them in application state.

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.