Segmented Control
Two to five exclusive options with a pill that glides to the selection. Arrow keys move and select.
- Category: Inputs
- Licence: Free, MIT
- Built with: React 19, Tailwind CSS 4, Motion
- Dependencies: motion, clsx, tailwind-merge
Examples
Segmented Control
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
options | { value: T; label: ReactNode; icon?: ReactNode; disabled?: boolean }[] | — | |
value | T | — | Controlled value. |
defaultValue | T | — | Initial value when uncontrolled. |
onValueChange | (value: T) => void | — | |
size | "sm" | "md" | "md" | |
aria-label | string | — |
About Segmented Control
Segmented Control is the iOS-style switcher for two to five exclusive options, with a pill that glides under the selection. It is the right control when the choices are few, short and always visible, like a billing period toggle.
Segmented Control is an input component for React 19, styled with Tailwind CSS 4 and animated with Motion. It drops into Next.js, Vite, Remix or Astro through the shadcn CLI as a single file you own.
When to use Segmented Control
- Monthly and yearly billing toggles on pricing pages.
- View switchers such as list, grid and board.
- Chart range pickers like day, week and month.
- Compact filters inside toolbars.
How it works
The selected pill is a single Motion layout element that moves between options, so the transition stays smooth however wide the labels are. It is a radiogroup with roving focus: arrow keys move and select, Tab leaves the group.
It is a real form control: it has an accessible name, works with the keyboard alone, shows a visible focus ring and announces its state to screen readers. With prefers-reduced-motion on, it holds still or settles instantly instead of animating.
Customizing Segmented Control
Every prop is documented in the API reference above with its type and default. The ones you will reach for first are listed here.
The Customize panel next to the preview lets you change size live, and the Code tab updates to match, so the snippet you copy already carries your values.
- options.
- value (T): Controlled value.
- defaultValue (T): Initial value when uncontrolled.
- size ("sm" | "md", default "md").
- aria-label (string).
Goes well with Segmented Control
Segmented Control is already composed into 3 ready-made sections, so you can see it in context or install the whole block.
- Pricing Tiers: Pricing section
- Features Versus: Features section
- Pricing Donation: Pricing section
- Range Slider: Six animated React range sliders on one accessible core: inline, tick, fluid, wave, bubble and ruler
- Button: An animated React button with six variants, spring press feedback and a width-stable loading state
- Switch: An animated React toggle switch whose thumb stretches when pressed, like a real switch
- Checkbox: An animated React checkbox: the check draws itself in, the box pops, indeterminate morphs to a dash
- Radio Group: An animated React radio group with roving focus and a highlight that glides between card options
Install Segmented Control
npx shadcn@latest add https://charcoalui.com/r/segmented-control.jsonSegmented Control is free and MIT licensed. The command copies segmented-control.tsx into components/ui and installs clsx, tailwind-merge; you can also copy the source from the Code tab by hand.
It pairs well with Gooey, a Pro piece: Liquid UI: pieces that touch melt into one another and stretch apart like goo, while text and icons stay perfectly crisp. An SVG filter plus springs, so it works with any markup.
Frequently asked questions
- How do I install Segmented Control?
- Run npx shadcn@latest add https://charcoalui.com/r/segmented-control.json. The shadcn CLI copies segmented-control.tsx into components/ui and installs motion, clsx, tailwind-merge. You can also copy the source from this page by hand.
- Is Segmented Control free for commercial use?
- Yes. Segmented Control is MIT licensed: use it in any personal or commercial project and change it however you like.
- Does Segmented Control work with Next.js?
- Yes. It is a client component for React 19 styled with Tailwind CSS 4, so it works in the Next.js App Router and Pages Router, Vite, Remix and Astro.
- Can an AI coding agent install Segmented Control?
- Yes. Connect the Charcoal UI MCP server (https://charcoalui.com/mcp) to Claude Code, Cursor or any MCP client; get_component returns Segmented Control's props and source and get_install_command returns the exact command.