Skip to main content

Segmented Control

A row of segments that switches between a few short options, like a view or an environment. A tinted thumb slides to the checked segment.

Desktop viewport
Tablet viewport
Mobile viewport

When to use

  • Switch between a few short options in one compact, inline row, such as a view, an environment, or a filter.
  • Prefer RadioGroup for a form field whose options need a description, or stack in a column.
  • Prefer Tabs when each option shows its own panel of content.
  • Prefer Select when the set is long, or the row has little space.

Controlled

Pass value and onValueChange to keep the checked segment in your own state. The control reports the new value on a click, a key, and a drag.

Desktop viewport
Tablet viewport
Mobile viewport

Icon segments

A segment can hold only an icon. Give each one its name in sr-only text, so a screen reader announces it. A segment whose children are an icon and sr-only text is square, like an IconButton. Set w-fit on the root, so the segments do not grow to fill the row.

Desktop viewport
Tablet viewport
Mobile viewport

Size

Set size on SegmentedControl.Root to set the height of the whole control, default md. The scale is the one Button, IconButton, and SplitButton use: xs, sm, md, lg, and xl. A control lines up with buttons of the same size in a toolbar. At xs, the labels are text-xs, so they have room inside the 16px thumb. Use a size-4 icon at xs and sm, and a size-5 icon from md up, as in an IconButton. A Button with appearance="link" has no box, so it has no height to match. The items do not accept size, so the items of one control always share one height.

Desktop viewport
Tablet viewport
Mobile viewport

With TanStack Form

Use @tanstack/react-form with zod to keep the control controlled in a form. Pass the field's name, value, and handleChange. Use Field.Set and Field.Legend to name the group and show its errors.

Desktop viewport
Tablet viewport
Mobile viewport

Composition

SegmentedControl.Root
└── SegmentedControl.Item

Radio semantics

SegmentedControl is a radio group of native radios. It shares its primitive with RadioGroup, so it has the same contract: role="radiogroup", one tab stop, arrow keys that move the checked segment, and form submission when it has a name. Each segment is a <div> with an invisible <input type="radio"> in it, so style a segment's state with has-[>input:checked]:, has-[>input:disabled]:, and has-[>input:focus-visible]:.

To change the value, click a segment, use the arrow keys, or drag the thumb with a mouse or a finger.

Dragging the thumb

A sideways drag on the checked segment moves the thumb with the pointer. On release, the thumb slides to the nearest enabled segment, and that segment becomes checked. A flick carries the thumb further. Past either end, the thumb meets resistance and stays inside the track. A drag that goes up or down more than sideways does not start, so the page still scrolls on a touch screen.

The thumb slides on every change: a click, a key, a drag, or a new value. With reduced motion, it moves at once.

API Reference

SegmentedControl.Root

The row of segments. It renders the radio group itself, so use it in place of RadioGroup.Root, never inside one.

The same props as RadioGroup.Root, including:

PropTypeDefaultDescription
value?stringThe controlled value of the checked segment.
defaultValue?stringThe value checked at first, when uncontrolled.
onValueChange?(value: string) => voidCalled with the new value when the checked segment changes.
disabled?booleanfalseWhen true, prevents interaction with every segment.
name?stringThe form field name. With a name, a form submits the value.
required?booleanfalseWhen true, a form submits only when a segment is checked.
form?stringThe id of the form the radios belong to.
aria-label?stringThe name of the control. Set it, or set aria-labelledby.

It also takes:

PropTypeDefaultDescription
size?"xs" | "sm" | "md" | "lg" | "xl""md"The height of the control: 24px, 28px, 36px, 40px, or 48px, as on Button.
Data AttributeValueDescription
data-slot"segmented-control"The control.
data-size"xs" | "sm" | "md" | "lg" | "xl"The size prop.
data-draggingpresent during a dragThe thumb follows the pointer. Presence-only.

SegmentedControl.Item

One segment. It grows to share the row and keeps its label on one line, so keep labels to one or two words. Inside Field.Control, the segment picks up aria-invalid, aria-errormessage, and aria-describedby.

PropTypeDefaultDescription
valuestringThe value the control reports when this segment is checked.
disabled?booleanWhen true, the segment cannot be checked.
Data AttributeValueDescription
data-slot"segmented-control-item"The segment: a <div> with its radio.
data-slot"segmented-control-item-label"The display: contents wrapper of the segment's children.
data-thumb-overpresent during a dragThe thumb is over this segment. Presence-only.