Segmented control
Also called segmented button or toggle button group
A compact row of two to five options in one pill-shaped track, where a sliding thumb marks the single selected option.
import { useId, useState } from 'react';
import { motion } from 'motion/react';
import { Radio } from '@base-ui/react/radio';
import { RadioGroup } from '@base-ui/react/radio-group';
const RANGES = ['Day', 'Week', 'Month'] as const;
type Range = (typeof RANGES)[number];
// Stiff and well damped: the thumb settles in about 250ms with no bounce.
const THUMB_SPRING = { type: 'spring', stiffness: 500, damping: 40 } as const;
export function ChartRangeControl() {
const [range, setRange] = useState<Range>('Week');
const id = useId();
// A radio group: one choice among several, with arrow-key support.
return (
<RadioGroup
value={range}
onValueChange={setRange}
aria-label='Chart range'
className='inline-flex rounded-lg bg-muted p-0.5'
>
{RANGES.map((option) => (
<Radio.Root
key={option}
value={option}
className='relative flex h-8 cursor-default items-center rounded-md px-4 text-sm font-medium text-muted-foreground outline-none select-none focus-visible:ring-2 focus-visible:ring-ring data-checked:text-foreground'
>
{option === range && (
<motion.span
layoutId={`${id}-thumb`}
transition={THUMB_SPRING}
className='absolute inset-0 rounded-md bg-background shadow-sm'
/>
)}
<span className='relative'>{option}</span>
</Radio.Root>
))}
</RadioGroup>
);
}Replace the Day, Week, and Month buttons above the chart with an iOS-style segmented control: a gray pill track with a white raised thumb that slides to the selected option using a spring (stiffness 500, damping 40). Make it a radio group so the arrow keys change the selection, and make each segment at least 32px tall.
Paste into Layerwise or any AI coding tool.
What is Segmented control?
A segmented control looks like a set of buttons fused into one rounded track. Exactly one segment is selected, and a raised thumb slides under it when you pick another. It comes from iOS, where it switches views such as Day, Week, and Month.
Use it to switch between a few views or modes of the same content: List and Grid, Monthly and Yearly pricing, or Day and Week in a chart. Keep it to about five short labels. To move between different sections of a page, use tabs, and for a setting that is simply on or off, use a toggle switch.
The sliding thumb is the signature detail. Move it with a spring that settles in about 250 to 300ms with little or no bounce, and compare it with an instant jump in the demo. Build it as a radio group with arrow-key support so screen readers announce it as one choice among several.
Often confused with
- Tabs
- Tabs move between different sections of content. A segmented control changes how the same content is shown.
- Radio button
- Both pick exactly one option. A segmented control packs a few short options into one compact bar, while radio buttons list them with room for longer labels and details.
Related terms
All termsTabs
A row of labels that switches between panels of related content in the same spot, showing one panel at a time.
Radio button
A round option in a group where choosing one clears the others, so people pick exactly one answer, like a plan or a shipping speed.
Spring animation
An animation driven by simulated spring physics in place of a fixed duration and curve, so motion can overshoot, settle, and react naturally.
Layout animation
An animation that smoothly moves and resizes elements when the layout changes, such as list items gliding to new spots after a sort or filter.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.