Segmented button
A segmented button sets one of two to four modes of the same content: which side of a card shows, which way a station scans, how cards print.
When to use
- A mode or view of the same content, chosen at once and kept visible: card side ("English" | "العربية"), scan direction ("Coming in" | "Going out"), print layout ("One card per page" | "A4 sheets"), what a history search looks at ("A place" | "A person").
- Appearance in settings: "System" | "Light" | "Dark" (the theme toggle builds it on this component).
- Two to four options whose short labels fit side by side, or stacked below 640px.
When not to use
| Need | Use instead |
|---|---|
| Panels of different content (sign in or create account, profile sections) | Tabs |
| An answer to a form question, submitted later | Choice cards or radios |
| Turning one thing on or off | A switch (Checkbox, radio, and switch) or an icon toggle |
| Filtering a list by several values at once | Filter chips |
| More than four options, or long labels | A select or a group of radios |
| An action | Buttons |
The boundary is the content: segments change a mode of what is already on screen; tabs swap what is on screen (D-CAI-16, canonical §10.8).
Anatomy
- Group. A
<fieldset>: a pill with a 1px--color-outlineedge on--color-surface, clipping its segments. - Name.
aria-label="…"on the fieldset, a visually hidden<legend>, oraria-labelledby="…"pointing at a visible label above the group. - Segment.
<button type="button">with[aria-pressed], 48px tall, with the state layer over its whole border box, its own divider included. - Divider. A 1px
--color-outlineline at the inline start of every segment after the first. - Icon (optional, 20px) and check (20px, FILL 1): the check replaces the icon on the selected segment.
- Label in
label-lg; it never wraps.
Variants
| Variant | Class | Use for | Key tokens |
|---|---|---|---|
| default | oa-segmented |
The group hugs its segments | edge --color-outline, fill --color-surface, selected --color-primary-container with --color-on-primary-container |
| wide | oa-segmented oa-segmented--wide |
The group fills its row and the segments share it equally (a station's direction switch on a phone); add oa-segmented--stack when the segments carry icons, because two icon-and-label segments do not fit side by side at 320px ("Coming in" and "Going out" lost 12px) |
as default |
| stacked | oa-segmented oa-segmented--stack |
Labels that do not fit side by side at 360px: below 640px (Tailwind sm:) the segments stack in a column with 16px corners |
--radius-box |
Segments carry an icon and words, or words only; keep one of the two through a group.
Sizes
| Size | Height | Padding | Type style | Icon |
|---|---|---|---|---|
| default | at least 48px, --size-button-md (min-h-12): scaled text grows the segment instead of clipping it |
24px inline, --space-6 (px-6) |
label-lg (16/24 600) |
20px, --size-icon-md |
The icon or check sits 8px from the label (--space-2). One size only (D-CAI-16, D-ARC-20).
Tokens
| Part | Property | Token (Tailwind) |
|---|---|---|
| Group | edge | 1px --color-outline (border border-outline) |
| Group | fill | --color-surface (bg-surface) |
| Group | corner | --radius-full (rounded-full); stacked --radius-box (rounded-box) |
| Segment | height, padding | --size-button-md, --space-6 (h-12 px-6) |
| Segment | label | --color-on-surface, --text-label-lg (text-label-lg) |
| Divider | line | 1px --color-outline (border-s border-outline) |
| Selected | fill and content | --color-primary-container, --color-on-primary-container |
| Icon, check | size | --size-icon-md |
| State layer | extent | the segment's border box: a segment after the first reaches over its own divider (inset-inline-start: -1px; stacked, inset-block-start: -1px) |
| State layer | opacity | --opacity-state-hover, --opacity-state-pressed |
| State layer | fade | --duration-short-3, --ease-standard |
| Focus | ring | --size-focus-ring solid --color-focus-ring, inset at --size-focus-inset (focus-visible:-outline-offset-4) |
| Disabled | label | --color-on-surface at 38% |
States
| State | What changes |
|---|---|
| Enabled | on-surface words on the page color. |
| Hover | Pointer devices only: the layer at --opacity-state-hover. |
| Focus-visible | The ring inset 4px inside the segment, because the group clips; the end segments follow the pill, so the ring keeps round ends (D-SEM-11, D-ARC-06). |
| Pressed | The layer at --opacity-state-pressed, at once. |
| Selected | [aria-pressed="true"]: primary-container with on-primary-container, and the check in place of the icon, the cue that does not depend on color (D-CAI-14). |
| Disabled | A segment that cannot apply: words at 38%, no layer. Rare; never disable the whole group to hide a mode. |
Behavior
- One segment is always selected. Pressing another selects it and applies the mode at once; pressing the selected one does nothing (D-CAI-16).
- Keyboard: Tab reaches each segment; Space or Enter selects it. The segments are buttons, not radios, so arrow keys do not move between them (D-CAI-16).
- Script contract: on press, set
[aria-pressed="true"]on that segment and[aria-pressed="false"]on the others, then apply the mode. Write the check element in every segment; the attribute decides which one shows. - Layout: the group hugs its segments and starts at the inline start of its column.
oa-segmented--widefills the row.oa-segmented--stackturns into a column below 640px (Tailwindsm:); use it whenever the labels do not fit at 360px in every language, and for every group of three options or more whose labels are translated (the Appearance group: "Système, Clair, Sombre" lost 41px side by side at 320px, the English group 12px). - Motion: only the layer and the colors change, over
--duration-short-3--ease-standard; nothing slides.
Accessibility
- Elements. A
<fieldset>(role group) named byaria-label="…", a hidden<legend>, oraria-labelledby="…"; each segment a<button type="button">with[aria-pressed](D-CAI-16). - Target. 48px tall; every segment is at least 48px wide with its padding.
- Contrast.
on-primary-containeronprimary-containeris 13.22:1 (light) and 9.06:1 (dark); the group'soutlineedge is 3:1 or more on every surface (D-COL-11). - Not by color alone. The check marks the selected segment.
- Language. A label in another language carries
lang("English"lang="en", "العربية"lang="ar"). - Forced colors. The group edge and dividers are drawn; the selected segment keeps its check; disabled words turn
GrayText. - Reduced motion. Instant.
RTL and languages
- The first segment sits at the inline start (the right in Arabic); dividers and round ends follow through logical properties. Pointing icons (
login,logout) takeoa-icon--mirror. - Arabic: "الاتجاه": "دخول" | "خروج" (Global ID).
- French runs about 26% longer than English, and up to 32% longer in short labels such as segments (canonical §3.7): "Une carte par page" | "Feuilles A4" does not fit side by side at 360px, so that group uses
oa-segmented--stack. Labels never wrap or truncate (D-TYP-15).
Content
- Name the group with a short phrase that says what changes: "Side of the card", "Direction", "Layout", "Look at", "Appearance" (Global ID's labels).
- Label each segment with one to three parallel words naming the mode, in sentence case: "Coming in" | "Going out"; "A place" | "A person"; "System" | "Light" | "Dark".
- No verbs on segments: they name a mode, not an action.
Do and don't
| Do | Don't |
|---|---|
| "Coming in" and "Going out" to set a station's scan direction. | Segments to swap between sign-in and sign-up panels (use tabs). |
| A check on the selected segment. | Color alone, or a raised white option on a gray track (1.06:1 in dark). |
oa-segmented--stack when French labels do not fit at 360px. |
Labels that wrap or truncate inside a segment. |
| Two to four segments. | Five segments, or a segmented button for yes and no in a form. |
Code
HTML (reference CSS)
From reference/snippets/actions.html:
<fieldset class="oa-segmented" aria-label="Side of the card">
<button type="button" class="oa-segmented__btn" aria-pressed="true" lang="en"><span class="oa-icon oa-segmented__check" aria-hidden="true" translate="no">check</span>English</button>
<button type="button" class="oa-segmented__btn" aria-pressed="false" lang="ar"><span class="oa-icon oa-segmented__check" aria-hidden="true" translate="no">check</span>العربية</button>
</fieldset>With icons, a visible label, stacked below 640px:
<div class="oa-stack oa-stack--tight">
<p id="ks-layout-label" class="oa-text-label-md">Layout</p>
<fieldset class="oa-segmented oa-segmented--stack" aria-labelledby="ks-layout-label">
<button type="button" class="oa-segmented__btn" aria-pressed="true"><span class="oa-icon oa-segmented__icon" aria-hidden="true" translate="no">crop_landscape</span><span class="oa-icon oa-segmented__check" aria-hidden="true" translate="no">check</span>One card per page</button>
<button type="button" class="oa-segmented__btn" aria-pressed="false"><span class="oa-icon oa-segmented__icon" aria-hidden="true" translate="no">grid_view</span><span class="oa-icon oa-segmented__check" aria-hidden="true" translate="no">check</span>A4 sheets</button>
</fieldset>
</div>Wide:
<fieldset class="oa-segmented oa-segmented--wide oa-segmented--stack" aria-label="Direction">
<button type="button" class="oa-segmented__btn" aria-pressed="true"><span class="oa-icon oa-icon--mirror oa-segmented__icon" aria-hidden="true" translate="no">login</span><span class="oa-icon oa-segmented__check" aria-hidden="true" translate="no">check</span>Coming in</button>
<button type="button" class="oa-segmented__btn" aria-pressed="false"><span class="oa-icon oa-icon--mirror oa-segmented__icon" aria-hidden="true" translate="no">logout</span><span class="oa-icon oa-segmented__check" aria-hidden="true" translate="no">check</span>Going out</button>
</fieldset>Arabic:
<div class="ks-row" dir="rtl" lang="ar">
<fieldset class="oa-segmented" aria-label="الاتجاه">
<button type="button" class="oa-segmented__btn" aria-pressed="true"><span class="oa-icon oa-icon--mirror oa-segmented__icon" aria-hidden="true" translate="no">login</span><span class="oa-icon oa-segmented__check" aria-hidden="true" translate="no">check</span>دخول</button>
<button type="button" class="oa-segmented__btn" aria-pressed="false"><span class="oa-icon oa-icon--mirror oa-segmented__icon" aria-hidden="true" translate="no">logout</span><span class="oa-icon oa-segmented__check" aria-hidden="true" translate="no">check</span>خروج</button>
</fieldset>
</div>Tailwind CSS v4
<fieldset aria-label="Side of the card" class="m-0 flex w-fit min-w-0 max-w-full overflow-hidden rounded-full border border-outline bg-surface p-0">
<button type="button" aria-pressed="true" lang="en" class="relative isolate inline-flex h-12 flex-1 items-center justify-center gap-2 border-s border-outline px-6 text-label-lg text-on-surface whitespace-nowrap cursor-pointer first-of-type:border-s-0 first-of-type:rounded-s-full last-of-type:rounded-e-full focus-visible:-outline-offset-4 aria-pressed:bg-primary-container aria-pressed:text-on-primary-container disabled:cursor-default disabled:text-on-surface/38 disabled:before:opacity-0 transition-[background-color,color] duration-short-3 ease-standard before:pointer-events-none before:absolute before:inset-0 not-first-of-type:before:-start-px before:-z-1 before:rounded-[inherit] before:bg-current before:opacity-0 before:transition-opacity before:duration-short-3 before:ease-standard before:content-[''] hover:before:opacity-(--opacity-state-hover) active:before:opacity-(--opacity-state-pressed) active:before:duration-0">English</button>
</fieldset>
<!-- Wide: the group fills its row (w-full in place of w-fit) -->
<fieldset class="w-full"></fieldset>
<!-- Stacked below 640px, only where the labels do not fit at 360px. The group adds: -->
<fieldset class="max-sm:w-full max-sm:flex-col max-sm:rounded-box"></fieldset>
<!-- each segment writes its pill ends from sm (in place of the unprefixed pair) and adds the column look; the state layer follows the divider to the top: -->
<button class="sm:first-of-type:rounded-s-full sm:last-of-type:rounded-e-full max-sm:flex-none max-sm:border-s-0 max-sm:border-t max-sm:first-of-type:border-t-0 max-sm:first-of-type:rounded-t-box max-sm:last-of-type:rounded-b-box max-sm:not-first-of-type:before:start-0 max-sm:not-first-of-type:before:-top-px"></button>The first-of-type variants (rather than first) keep the first segment right when a visually hidden <legend> comes before it. Icons are the family Icon at text-(length:--size-icon-md); the selected segment shows the check (filled) in place of its icon. shadcn/ui: ToggleGroup becomes the segmented button (D-CAI-16).
React
| Prop | Type | Default | Description |
|---|---|---|---|
| options | ReadonlyArray<{ value: string; label: string; icon?: string; lang?: string }> |
required | Two to four segments; the check replaces a segment's icon when chosen. |
| value | string | required | The selected segment. |
| onValueChange | (value: string) => void |
required | Called when another segment is pressed. |
| label | string | none | Names the group (aria-label="…"); or pass labelledBy. |
| labelledBy | string | none | The id of a visible label above the group. |
| wide | boolean | false | Fill the row. |
| stack | boolean | false | Stack below 640px. |
<SegmentedButton
label={t('station.scanner.direction.label')}
value={direction}
onValueChange={setDirection}
options={[
{ value: 'in', label: t('station.scanner.direction.in'), icon: 'login' },
{ value: 'out', label: t('station.scanner.direction.out'), icon: 'logout' },
]}
wide
/>