Binary choice
<forma-binary-choice>
A two-option radio-backed answer that preserves Unanswered as distinct from false.
- Authoring tag
<forma-binary-choice>- Category
- Assessment and survey
- Behavior owner
- Native HTML
- Canonical source
patterns/binary-choice.html
Purpose
Binary choice answers a yes/no, true/false or agree/disagree question with two native radios in one group. Because no radio starts checked, an untouched question stays Unanswered and submits nothing, which is different from an explicit No. The options render as a joined segmented bar; the checked option takes the inverse surface. The browser owns selection, arrow-key movement, required validation and reset.
Use when
- An assessment or survey asks a yes/no question and Unanswered must remain distinguishable from No.
- A question has two (or a small bounded number of) mutually exclusive answers with short labels.
- The answer is recorded on submit rather than applied immediately.
Avoid when
- The control is an on/off setting that takes effect immediately: use Switch.
- The user is confirming consent or ticking an independent item: use Checkbox.
- The options are ordered steps on a scale: use Ordinal scale.
- Options need descriptions or long labels: use Choice group cards.
Behavior to know
- Two native radios sharing a
name; the group is announced by the fieldset legend. - Unanswered is the absence of a checked radio, not a third value.
- Options sit side by side on wide screens and stack into full-width rows below 44rem.
- Selection is shown by an inverse surface and, in forced colors, system Highlight.
Basic example
The smallest correct markup: the canonical pattern from patterns/binary-choice.html inside its public tag. Copy this first, then adapt labels, names and state.
Minimal binary choice
Rendered from the canonical pattern file.
<forma-binary-choice class="forma-component-tag">
<fieldset class="forma-binary-choice">
<legend class="forma-binary-choice__legend">Is automated deployment currently in use?</legend>
<p class="forma-field__description" id="binary-choice-help">Choose one response. An unanswered question remains distinct from No.</p>
<div class="forma-binary-choice__options" aria-describedby="binary-choice-help">
<label class="forma-binary-option">
<input type="radio" name="automated-deployment" value="yes" required>
<span>Yes</span>
</label>
<label class="forma-binary-option">
<input type="radio" name="automated-deployment" value="no">
<span>No</span>
</label>
</div>
</fieldset>
</forma-binary-choice>
Click or tap the code once to select all of it, then copy.
Examples
True/false with a Don't know answer
A knowledge check where Don't know is a legitimate answer. It shares the radio name so it is mutually exclusive, but sits in the separate special-choices row so it is not read as a third point on the true/false axis.
<forma-binary-choice class="forma-component-tag">
<fieldset class="forma-binary-choice">
<legend class="forma-binary-choice__legend">Backups are encrypted at rest in every region.</legend>
<div class="forma-binary-choice__options">
<label class="forma-binary-option"><input type="radio" name="binary-unknown-encryption" value="true" required><span>True</span></label>
<label class="forma-binary-option"><input type="radio" name="binary-unknown-encryption" value="false"><span>False</span></label>
</div>
<div class="forma-special-choices" aria-label="Other responses">
<label class="forma-special-choice"><input type="radio" name="binary-unknown-encryption" value="unknown"><span>Don't know</span></label>
</div>
</fieldset>
</forma-binary-choice>
Click or tap the code once to select all of it, then copy.
Answered No after a validation error
The question was submitted empty, then answered. No is checked; the application has removed aria-invalid and the error. An explicit No is a real answer, unlike the untouched state.
<forma-binary-choice class="forma-component-tag">
<fieldset class="forma-binary-choice">
<legend class="forma-binary-choice__legend">Is multi-factor authentication enforced for administrators?</legend>
<p class="forma-field__description" id="binary-answered-help">Answer for the production environment only.</p>
<div class="forma-binary-choice__options">
<label class="forma-binary-option"><input type="radio" name="binary-answered-mfa" value="yes" required aria-describedby="binary-answered-help"><span>Yes</span></label>
<label class="forma-binary-option"><input type="radio" name="binary-answered-mfa" value="no" checked aria-describedby="binary-answered-help"><span>No</span></label>
</div>
</fieldset>
</forma-binary-choice>
Click or tap the code once to select all of it, then copy.
Answer locked after sign-off
A response recorded in a previous, signed-off review. Both radios are disabled, so the answer is shown but excluded from focus and submission; the description explains why it cannot change.
<forma-binary-choice class="forma-component-tag">
<fieldset class="forma-binary-choice" disabled aria-describedby="binary-locked-help">
<legend class="forma-binary-choice__legend">Was the incident disclosed to affected customers?</legend>
<p class="forma-field__description" id="binary-locked-help">Locked: this review was signed off on 12 March. Reopen the review to change the answer.</p>
<div class="forma-binary-choice__options">
<label class="forma-binary-option"><input type="radio" name="binary-locked-disclosed" value="yes" checked><span>Yes</span></label>
<label class="forma-binary-option"><input type="radio" name="binary-locked-disclosed" value="no"><span>No</span></label>
</div>
</fieldset>
</forma-binary-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.
Agree or disagree on a phone
Below 44rem the bar becomes two full-width stacked rows, each at least 44px tall.
What changes at narrow widths
- The options switch from a side-by-side inline grid to a single column that fills the width.
- The divider moves from the inline-start edge to the block-start edge between the stacked options.
- Each option keeps a 2.75rem (44px) minimum height, and the whole label is the tap target.
- Long legends wrap; nothing scrolls horizontally at 320px.
<forma-binary-choice class="forma-component-tag">
<fieldset class="forma-binary-choice">
<legend class="forma-binary-choice__legend">On-call engineers have the access they need during an incident.</legend>
<div class="forma-binary-choice__options">
<label class="forma-binary-option"><input type="radio" name="binary-mobile-access" value="agree" required><span>Agree</span></label>
<label class="forma-binary-option"><input type="radio" name="binary-mobile-access" value="disagree"><span>Disagree</span></label>
</div>
</fieldset>
</forma-binary-choice>
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 | radio | — | Required. Radios, not a checkbox, so Unanswered stays representable. |
name | input | string shared by both options | — | Groups the options so only one can be checked. Must be unique per question on the page. |
value | input | string | — | Submitted answer. The application maps it to meaning; Forma attaches none. |
required | first input | boolean | absent | Native required-group validation: the form cannot submit while the question is Unanswered. |
checked | input | boolean | absent | Restores a previously saved answer. Leave both unchecked for Unanswered. |
disabled | fieldset or input | boolean | absent | Locks the answer; disabled radios are not focusable or submitted. |
aria-describedby | fieldset or input | id list | — | Associates help or error text with the question. |
| Hook | Kind | Values or default | Description |
|---|---|---|---|
.forma-binary-choice | Block class | — | Root fieldset with browser border and padding removed. |
.forma-binary-choice__legend | Element class | — | Question text, rendered bold above the options. |
.forma-binary-choice__options | Element class | — | Bordered inline grid that joins the options into one bar; stacks below 44rem. |
.forma-binary-option | Block class | — | Label wrapping one radio and its text. At least 44px tall; the radio is visually hidden but remains the focus and hit target. |
| Keys | Result |
|---|---|
| Tab / Shift+Tab | Moves focus into the group (to the checked radio, or the first radio when Unanswered) and out of it. |
| Arrow keys | Native radio group behavior: moves between options and selects the one that receives focus. |
| Space | Selects the focused option when none is checked. |
| Event | Description |
|---|---|
input / change | Native events from the radio that becomes checked. |
Form behavior
Submits name=value for the checked radio only. An Unanswered question submits nothing and fails required validation; form reset restores the initial checked attribute.
States
| State | How it is expressed | Presentation |
|---|---|---|
| Unanswered | no checked radio | Both options show the neutral surface. Distinct from No. |
| Selected | :checked | The chosen option takes the inverse surface and text color. |
| Focus | :focus-visible on the radio | Two-tone focus ring drawn around the option label. |
| Disabled | disabled on fieldset or input | Native disabled state; the answer is visible but not editable or submitted. |
| Invalid | aria-invalid plus an application message | Forma adds no invalid styling to the options; render a Validation message next to the group. |
Accessibility
Forma provides
- Keeps native radios as the focusable, labelled elements, so name, checked state and arrow-key behavior come from the platform.
- Makes the whole option label the pointer and touch target at a 44px minimum height.
- Shows selection with a surface change plus Highlight/HighlightText in forced-colors mode, and a visible focus ring.
Your application supplies
- Write a legend that states the full question.
- Keep radio names unique per question and never pre-check an answer the user has not given.
- Render and associate a validation message when a required question is left Unanswered.
- Explain any disabled or locked answer in visible text.
Responsive behavior
- Wide: an inline grid with columns of at least 6rem each, capped at 100% width.
- Below 44rem: a single column that fills the width; the divider becomes horizontal.
- Labels wrap inside each option; the bar never forces horizontal overflow.
Motion
- Background, border and text color interpolate over the shared perceptual duration (about 120ms) when an option is selected or hovered. Selection itself is immediate.
- Timing is identical for both options, so motion never implies which answer is preferred.
- Under
prefers-reduced-motion: reducethe foundation reduces transitions to effectively instant.
Usage guidance
Do
- Use short, parallel labels such as Yes/No or True/False.
- Offer Don't know or Not applicable through Special choice when they are legitimate answers.
Avoid
- Pre-selecting No as a default; it erases the difference between unanswered and answered.
- Replacing the radios with a switch for assessment answers.
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.