Assessment and survey

Pairwise choice

<forma-pairwise-choice>

A focused two-alternative comparison using ordinary choice semantics.

Authoring tag
<forma-pairwise-choice>
Behavior owner
Native HTML
Canonical source
patterns/pairwise-choice.html

Purpose

A pairwise choice asks the user to pick one of two described alternatives, shown side by side as large cards with an "or" between them. It is a native radio group: both cards are labels with visually hidden radios, so the browser owns selection, keyboard movement and required validation. The "Option A / Option B" eyebrow and the "or" separator are presentation; the application decides how many pairs to show, in which order, and what a preference means.

Use when

  • A decision or prioritisation exercise compares two alternatives at a time.
  • Each alternative needs a title and a short description to be understood.
  • A series of pairwise comparisons is used to derive an overall preference.

Avoid when

Behavior to know

  • Two equal-width cards with an auto-width separator column.
  • The whole card is the click and touch target (minimum 5rem tall).
  • The separator is aria-hidden; the radio group semantics communicate that only one can be chosen.
  • Cards stack vertically below 44rem with the separator centred between them.

Basic example

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

Canonical

Minimal pairwise choice

Rendered from the canonical pattern file.

Which is more important for this decision?
HTML · Minimal pairwise choice Raw HTML for HTML · Minimal pairwise choice
<forma-pairwise-choice class="forma-component-tag">
<fieldset class="forma-pairwise">
  <legend class="forma-pairwise__legend">Which is more important for this decision?</legend>

  <div class="forma-pairwise__options">
    <label class="forma-pairwise__option">
      <input type="radio" name="priority-comparison" value="reliability" required>
      <span class="forma-pairwise__eyebrow">Option A</span>
      <strong>Reliability</strong>
      <span>Prefer predictable operation and recovery.</span>
    </label>

    <span class="forma-pairwise__versus" aria-hidden="true">or</span>

    <label class="forma-pairwise__option">
      <input type="radio" name="priority-comparison" value="speed">
      <span class="forma-pairwise__eyebrow">Option B</span>
      <strong>Delivery speed</strong>
      <span>Prefer faster change and deployment.</span>
    </label>
  </div>
</fieldset>
</forma-pairwise-choice>

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

Examples

Scenario

Second option chosen

Comparison 4 of 10 in a prioritisation exercise with Option B selected. The selected card takes the inverse surface.

Which should the platform team invest in next quarter?

Comparison 4 of 10

HTML · Second option chosen Raw HTML for HTML · Second option chosen
<forma-pairwise-choice class="forma-component-tag">
  <fieldset class="forma-pairwise" aria-describedby="pairwise-selected-position">
    <legend class="forma-pairwise__legend">Which should the platform team invest in next quarter?</legend>
    <p class="forma-field__description" id="pairwise-selected-position">Comparison 4 of 10</p>
    <div class="forma-pairwise__options">
      <label class="forma-pairwise__option">
        <input type="radio" name="pairwise-selected-investment" value="observability" required>
        <span class="forma-pairwise__eyebrow">Option A</span>
        <strong>Observability</strong>
        <span>Unified tracing and log search across all services.</span>
      </label>
      <span class="forma-pairwise__versus" aria-hidden="true">or</span>
      <label class="forma-pairwise__option">
        <input type="radio" name="pairwise-selected-investment" value="self-service" checked>
        <span class="forma-pairwise__eyebrow">Option B</span>
        <strong>Self-service environments</strong>
        <span>Teams create preview environments without a ticket.</span>
      </label>
    </div>
  </fieldset>
</forma-pairwise-choice>

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

Scenario

Comparison with a No preference answer

When a tie is a legitimate answer, it is offered as a special choice sharing the radio name, below the two cards rather than as a third card between them.

Which matters more for this service?
HTML · Comparison with a No preference answer Raw HTML for HTML · Comparison with a No preference answer
<forma-pairwise-choice class="forma-component-tag">
  <fieldset class="forma-pairwise">
    <legend class="forma-pairwise__legend">Which matters more for this service?</legend>
    <div class="forma-pairwise__options">
      <label class="forma-pairwise__option">
        <input type="radio" name="pairwise-tie-priority" value="latency" required>
        <span class="forma-pairwise__eyebrow">Option A</span>
        <strong>Low latency</strong>
        <span>Responses under 100ms at the 99th percentile.</span>
      </label>
      <span class="forma-pairwise__versus" aria-hidden="true">or</span>
      <label class="forma-pairwise__option">
        <input type="radio" name="pairwise-tie-priority" value="cost">
        <span class="forma-pairwise__eyebrow">Option B</span>
        <strong>Low running cost</strong>
        <span>Stay within the current infrastructure budget.</span>
      </label>
    </div>
    <div class="forma-special-choices" aria-label="Other responses">
      <label class="forma-special-choice"><input type="radio" name="pairwise-tie-priority" value="no-preference"><span>No preference</span></label>
    </div>
  </fieldset>
</forma-pairwise-choice>

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

Stacked comparison on a phone

Below 44rem the cards stack full width with the separator centred between them.

Viewport width

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

What changes at narrow widths

  • The three-column grid becomes one column: Option A, the "or" separator, then Option B, preserving source order.
  • Both cards take the full width, so long titles and descriptions wrap rather than truncate.
  • Each card keeps its 5rem minimum height; the entire card is the tap target.
  • Nothing scrolls horizontally at 320px, in portrait or landscape.
HTML · Stacked comparison on a phone Raw HTML for HTML · Stacked comparison on a phone
<forma-pairwise-choice class="forma-component-tag">
  <fieldset class="forma-pairwise">
    <legend class="forma-pairwise__legend">Which would you rather have?</legend>
    <div class="forma-pairwise__options">
      <label class="forma-pairwise__option">
        <input type="radio" name="pairwise-mobile-tradeoff" value="fewer-meetings" required>
        <span class="forma-pairwise__eyebrow">Option A</span>
        <strong>Fewer meetings</strong>
        <span>Two meeting-free days each week.</span>
      </label>
      <span class="forma-pairwise__versus" aria-hidden="true">or</span>
      <label class="forma-pairwise__option">
        <input type="radio" name="pairwise-mobile-tradeoff" value="faster-reviews">
        <span class="forma-pairwise__eyebrow">Option B</span>
        <strong>Faster reviews</strong>
        <span>Code reviews answered within four working hours.</span>
      </label>
    </div>
  </fieldset>
</forma-pairwise-choice>

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
typeinputradio—Required. Two radios sharing one name.
nameinputstring—Groups the two alternatives. Unique per comparison.
valueinputstring—Submitted choice. The application derives preferences; Forma attaches no meaning to A or B.
requiredfirst inputbooleanabsentNative required-group validation.
checkedinputbooleanabsentRestores a saved choice.
aria-hidden.forma-pairwise__versustrue—Keeps the decorative "or" out of the accessibility tree.
aria-describedbyfieldsetid list—Associates help text such as the comparison position.
CSS hooks (derived from dist/all.css)
HookKindValues or defaultDescription
.forma-pairwiseBlock class—Root fieldset with browser border and padding removed.
.forma-pairwise__eyebrowElement class—Small uppercase monospace label such as Option A.
.forma-pairwise__legendElement class—Comparison question.
.forma-pairwise__optionElement class—Bordered card label with a visually hidden radio; at least 5rem tall.
.forma-pairwise__optionsElement class—Three-column grid: option, separator, option. One column below 44rem.
.forma-pairwise__versusElement class—The decorative "or" separator.
Keyboard interaction
KeysResult
Tab / Shift+TabMoves focus into and out of the comparison.
Arrow keysNative radio behavior: switches and selects between the two alternatives (and any shared special answer).
SpaceSelects the focused alternative when none is checked.
Events
EventDescription
input / changeNative events from the checked radio.

Form behavior

Submits name=value for the chosen alternative; unanswered submits nothing and fails required validation.

States

Pairwise choice states
StateHow it is expressedPresentation
Unansweredno checked radioBoth cards neutral.
Selected:checkedThe chosen card takes the inverse surface.
Focus:focus-visible on the radioTwo-tone focus ring around the card.

Accessibility

Forma provides

  • Uses a native radio group in a fieldset, so the question and the exclusive choice are announced by the platform.
  • Makes each card's full area the target and keeps the title and description inside the label.
  • Uses Highlight/HighlightText for the selected card in forced-colors mode.

Your application supplies

  • Keep the accessible name meaningful: the card's strong title is read as part of the label, so do not rely on the eyebrow alone.
  • Randomise or balance A/B order in application logic if position bias matters.
  • Announce progress through a series of comparisons with visible text or Survey progress.

Responsive behavior

  • Wide: minmax(0, 1fr) auto minmax(0, 1fr) keeps the two cards equal regardless of text length.
  • Below 44rem: one column with the separator centred.
  • Card text wraps; there is no horizontal overflow.

Motion

  • No animation: the selected card switches surface immediately. The pairwise card is not in the shared transitioned option list.

Usage guidance

Do

  • Give both alternatives parallel titles and descriptions of similar length.
  • Offer No preference as a Special choice when ties are allowed.

Avoid

  • Styling one option as the recommended default.
  • Using pairwise comparison for yes/no questions.

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.