Selection and choice

Segmented control

<forma-segmented-control>

Radio-backed compact selection with visible selected and focus states; where supported, one light-inertial selection indicator travels between segments without delaying native selection.

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

Purpose

A segmented control shows two to five short, mutually exclusive options side by side, with the chosen one filled. It is a native radio group: each forma-segment is a label wrapping a visually hidden input type="radio", and all radios share one name. The browser owns selection, arrow-key movement, form submission and reset. Forma draws the bordered track, the filled selected segment and the focus ring, and in browsers with CSS anchor positioning one indicator travels to the newly selected segment. The selection itself is always immediate.

Use when

  • Users switch between a few short, mutually exclusive modes or views: density, units, list/board, day/week/month.
  • All options should be visible at once and fit on one or two lines.
  • The choice applies immediately or is submitted with a form as one value.

Avoid when

  • Options need descriptions or long labels: use Choice group.
  • More than about five options, or options that change often: use Select.
  • Several options can be chosen together: use Multi-choice or checkboxes; this control is single-select only.
  • The segments switch between panels of content with tab semantics: use Tabs.
  • The setting is on/off: use Switch.

Behavior to know

  • Selection is native radio state; :checked drives the filled segment.
  • Each segment is at least 44px tall and the whole label is the hit target.
  • The selected segment is shown by an inverse fill, not by color hue alone, and by system Highlight in forced-colors mode.
  • On narrow screens (44rem and below) the control fills the width and segments wrap instead of shrinking.

Basic example

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

Canonical

Minimal segmented control

Rendered from the canonical pattern file.

Density
HTML · Minimal segmented control Raw HTML for HTML · Minimal segmented control
<forma-segmented-control class="forma-component-tag">
<fieldset class="forma-field">
  <legend class="forma-field__label">Density</legend>
  <div class="forma-segmented">
    <label class="forma-segment">
      <input type="radio" name="density" value="comfortable" checked>
      <span>Comfortable</span>
    </label>
    <label class="forma-segment">
      <input type="radio" name="density" value="compact">
      <span>Compact</span>
    </label>
  </div>
</fieldset>
</forma-segmented-control>

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

Examples

Scenario

Calendar range picker

Four short options with Week preselected. The fieldset legend names the choice, so screen readers announce "Show, radio group" and each option as "Week, radio button, 2 of 4, checked".

Show
HTML · Calendar range picker Raw HTML for HTML · Calendar range picker
<forma-segmented-control class="forma-component-tag">
  <fieldset class="forma-field">
    <legend class="forma-field__label">Show</legend>
    <div class="forma-segmented">
      <label class="forma-segment"><input type="radio" name="segmented-control-calendar-range" value="day"><span>Day</span></label>
      <label class="forma-segment"><input type="radio" name="segmented-control-calendar-range" value="week" checked><span>Week</span></label>
      <label class="forma-segment"><input type="radio" name="segmented-control-calendar-range" value="month"><span>Month</span></label>
      <label class="forma-segment"><input type="radio" name="segmented-control-calendar-range" value="year"><span>Year</span></label>
    </div>
  </fieldset>
</forma-segmented-control>

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

Scenario

No default selection, heavier indicator

A required choice with nothing preselected, so the user must decide. With no checked radio there is no indicator and no filled segment. data-forma-motion-weight="heavy" gives the indicator a slower, more settled travel once a choice is made; weight is presentation only and says nothing about the options.

Billing cycle

Required. You can change this before your first invoice.

HTML · No default selection, heavier indicator Raw HTML for HTML · No default selection, heavier indicator
<forma-segmented-control class="forma-component-tag">
  <fieldset class="forma-field">
    <legend class="forma-field__label">Billing cycle</legend>
    <p class="forma-field__description" id="segmented-control-no-default-heavy-help">Required. You can change this before your first invoice.</p>
    <div class="forma-segmented" data-forma-motion-weight="heavy">
      <label class="forma-segment"><input type="radio" name="segmented-control-no-default-heavy" value="monthly" required aria-describedby="segmented-control-no-default-heavy-help"><span>Monthly</span></label>
      <label class="forma-segment"><input type="radio" name="segmented-control-no-default-heavy" value="annual" aria-describedby="segmented-control-no-default-heavy-help"><span>Annual</span></label>
    </div>
  </fieldset>
</forma-segmented-control>

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

Wrapping segments on a phone

Five options, one with a long label, at phone width. The control stretches to the full width and segments that do not fit move to a second row rather than shrinking below a usable size.

Viewport width

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

What changes at narrow widths

  • At 44rem and below forma-segmented takes the full inline size and each segment flexes from a min(10rem, 100%) basis, so segments share the width evenly.
  • When the options do not fit on one row they wrap to further rows; nothing scrolls horizontally at 320px.
  • Every segment keeps its 44px minimum height, and the whole segment label is the tap target.
  • Wrapping changes only the visual rows. Arrow-key order and the radio group's order stay in source order.
HTML · Wrapping segments on a phone Raw HTML for HTML · Wrapping segments on a phone
<forma-segmented-control class="forma-component-tag">
  <fieldset class="forma-field">
    <legend class="forma-field__label">Distance unit</legend>
    <div class="forma-segmented">
      <label class="forma-segment"><input type="radio" name="segmented-control-mobile-wrapping-segments" value="m" checked><span>Metres</span></label>
      <label class="forma-segment"><input type="radio" name="segmented-control-mobile-wrapping-segments" value="km"><span>Kilometres</span></label>
      <label class="forma-segment"><input type="radio" name="segmented-control-mobile-wrapping-segments" value="ft"><span>Feet</span></label>
      <label class="forma-segment"><input type="radio" name="segmented-control-mobile-wrapping-segments" value="mi"><span>Miles</span></label>
      <label class="forma-segment"><input type="radio" name="segmented-control-mobile-wrapping-segments" value="nmi"><span>Nautical miles</span></label>
    </div>
  </fieldset>
</forma-segmented-control>

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. Each segment is a native radio.
nameinputstring—Required and shared by every radio in one control; it makes them one exclusive group and is the submitted field name. Unique per control on the page.
valueinputstring"on"Submitted value of the selected segment.
checkedinputbooleanabsentInitial selection. Omit on all radios when the user must make an active choice.
requiredinputbooleanabsentNative constraint: the form cannot submit until one segment is selected. Put it on one radio of the group.
aria-describedbyinputid—Links help text to the options.
data-forma-motion-weight.forma-segmentedlight | standard | heavylightPerceived mass of the travelling indicator.
CSS hooks (derived from dist/all.css)
HookKindValues or defaultDescription
.forma-segmentedBlock class—The track: an inline flex row with a functional border, secondary surface and a 2px inner gap. Also the anchor scope and host of the travelling indicator (::before).
[data-forma-motion-weight]Attribute hook"heavy", "light", "standard"Presentation-only perceived mass for the selection indicator: light (default for this control), standard or heavy. Never encodes importance or preference.
.forma-segmentBlock class—One option: a label containing the radio and a text span. At least 44px tall; filled with the inverse surface when its radio is checked.
Keyboard interaction
KeysResult
Tab / Shift+TabMoves focus into the group (to the checked segment, or the first when none is checked) and out of it. The group is one tab stop.
Arrow Right / Arrow DownMoves to and selects the next segment, wrapping to the first (native radio behavior).
Arrow Left / Arrow UpMoves to and selects the previous segment, wrapping to the last.
SpaceSelects the focused segment when none is selected yet.
Events
EventDescription
input / changeNative events fired by the newly selected radio. Listen on the fieldset for change to apply a view or setting.

Form behavior

Submits one name=value pair for the selected segment, nothing when none is selected. Supports required and native validity; form reset restores the initially checked segment.

States

Segmented control states
StateHow it is expressedPresentation
Unselectedno checked radioTransparent segment on the secondary surface. With no checked radio in the group, no indicator is drawn.
Selected:checked radioInverse (dark) surface with inverse text. With anchor positioning the fill is the travelling indicator; otherwise it is the segment's own background.
Focus:focus-visible on the radioTwo-tone focus ring around the focused segment.
Pressed:active on the radioThe label text scales to 97% while pressed; the segment (hit target) does not move.
Disableddisabled on a radioNative: cannot be selected or focused. No distinct visual treatment is provided.

Accessibility

Forma provides

  • Keeps native radios as the focusable, labelled elements, so group semantics, position in set and arrow-key selection come from the platform.
  • Keeps the radio topmost in the segment for direct and assistive hit-testing.
  • Shows selection with a fill contrast (inverse surface) and, in forced-colors mode, Highlight/HighlightText with the indicator removed.
  • Draws a visible focus ring on the segment that contains the focused radio.

Your application supplies

  • Wrap the control in a fieldset with a legend (or give the group an accessible name).
  • Use short, parallel labels; move long explanations to help text linked with aria-describedby.
  • Explain disabled options in text, since they are not visually distinct.
  • If selecting a segment changes content elsewhere, make that change discoverable (for example a heading update or live region).

Responsive behavior

  • Above 44rem the control is inline-sized to its content (display: inline-flex, max-inline-size: 100%) and wraps if the container is narrower.
  • At 44rem and below it takes the full width and segments flex evenly from a min(10rem, 100%) basis, wrapping into additional rows.
  • Segments never shrink below their 44px height and labels wrap instead of being truncated.
  • Equal-width versus content-sized modes, icon segments and a horizontal-overflow strategy are not provided.

Motion

  • Where CSS anchor positioning with anchor-scope is supported, one indicator (::before) travels to the selected segment using the light inertial duration and damped easing (no overshoot), so it never implies a neighbouring option.
  • data-forma-motion-weight changes the indicator's perceived mass; light is the default for this control.
  • Segment background and text color change by perceptual interpolation; pressing compresses only the label text layer, never the hit target.
  • Native selection is immediate. The indicator is presentation that follows the checked state and can be interrupted by the next selection.
  • Without anchor positioning, under prefers-reduced-motion: reduce, and in forced-colors mode the indicator is removed and the checked segment's own fill is the complete presentation; press compression is also removed under reduced motion.

Motion weights

Forma motion is physics-derived: perceived mass changes how a surface accelerates and settles, never what state it is in. Compare the three presentation weights of the same markup:

lightpresentation only
Density
standardpresentation only
Density
heavypresentation only
Density

Usage guidance

Do

  • Keep labels to one or two words and roughly equal length.
  • Preselect a sensible default only when one exists; leave all unchecked when the user must decide.

Avoid

  • Using a segmented control for navigation between pages or panels without tab semantics.
  • Putting more options in than fit on two rows at 320px.
  • Using motion weight to suggest one option is more important.

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.