shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A segment group is a short row of options where one is picked at a time, often called a segmented control, with a highlight that slides to the choice. It suits a setting that changes something in place: list or grid, monthly or yearly, day, week or month.
When each option should show its own panel, use Tabs. In a form, or when the options need a line of description, a Radio Group reads better.
Installation
Anatomy

Usage
import {
SegmentGroup, SegmentGroupItem, SegmentGroupItemText,
} from "@/components/ui/segment-group";const SegmentGroupDemo = () => (
<SegmentGroup
aria-label="Settings section"
className="rounded-lg"
defaultValue="Profile"
>
{items.map((item) => (
<SegmentGroupItem className="px-2 py-1.5 text-sm" key={item} value={item}>
<SegmentGroupItemText>{item}</SegmentGroupItemText>
</SegmentGroupItem>
))}
</SegmentGroup>
);
const items = ["Profile", "Account", "Security", "Notifications"];The group renders its own indicator, so the snippet has none. The selected SegmentGroupItem carries data-checked on every base and framework: style it with a variant such as data-checked:font-medium, and the other items with not-data-checked:.
Accessibility
SegmentGroup is a radiogroup and each item is a radio that reports whether it is checked, so a screen reader announces the options as one set and says which is on. The group is a single tab stop on the checked item, and the arrow keys move the choice. Naming the group is left to you: pass aria-label, or aria-labelledby with the id of a visible heading, to SegmentGroup. Without either, a screen reader announces a radio group with no name. An item that shows only an icon needs aria-label on its SegmentGroupItem.
- Tab
- Moves focus into the group, onto the checked item when there is one.
- Space
- When focus is on an unchecked item, checks it.
- Arrow Right
- Moves focus to the next item and checks it, skipping disabled items, and from the last item back to the first. Works in either orientation.
- Arrow Down
- Moves focus to the next item and checks it, skipping disabled items, and from the last item back to the first. Works in either orientation.
- Arrow Left
- Moves focus to the previous item and checks it, skipping disabled items, and from the first item to the last. Works in either orientation.
- Arrow Up
- Moves focus to the previous item and checks it, skipping disabled items, and from the first item to the last. Works in either orientation.
Demos
Controlled
Profile starts picked among four settings sections, and the parent's state holds the value. Each change arrives as an object whose value is the new string, and the demo writes it back. Hold the value when something else on the page follows the choice, such as a heading or the content below. Otherwise defaultValue is enough.
Custom indicator
The group already renders its indicator, so this demo restyles it instead of drawing a second pill: a class on SegmentGroup tints the element whose data-slot is segment-group-indicator with a translucent primary. Security is disabled, and the arrow keys skip it. Restyle the indicator this way to match a brand color or the surface behind the group.
Disabled
With disabled on SegmentGroup, every item is off, the selected Profile included, and the highlight stays where it was. Nothing answers a click or a key. Use it while the choice is shown but locked, for example until a form above it is valid. To lock a single option, disable that item and leave the rest alone.
Disabled item
Security has disabled on its own SegmentGroupItem, so a click does nothing and the arrow keys pass over it, while the other three still work. Use it for a section the current plan doesn't include, or a step the person hasn't reached yet. The item stays in the row, dimmed, so the missing choice isn't a mystery.
Form
Monthly and Yearly sit in a form under a Billing period heading, which names the group through aria-labelledby. With name set to billing, the checked item's value goes out with the form, and the line under Continue shows what was sent. Use it for a choice that travels with the rest of a form, such as a plan or a delivery speed.
Indicator on hover
The highlight follows the pointer: hovering an item points the controlled value at it, a click commits it, and leaving returns the highlight to the committed choice. There is no hover prop, only state. While the pointer rests on an item, that item is the group's value, so keep this to a view switcher that sits outside a form.
Orientation horizontal
Setting orientation to horizontal, the default, puts the four items in one row exactly as in the first demo, with the highlight sliding sideways. Writing it out helps when the orientation comes from a prop that is vertical on other screens. The row suits labels short enough to fit the width without wrapping.
Orientation vertical
orientation set to vertical stacks the four items in a column, each row as wide as the group, and the highlight moves up and down. Use a column in a sidebar, or when the labels are too long for one row. The arrow keys work as they do in a row, with Left and Right moving the choice as well as Up and Down.
Variant underline
variant set to underline drops the filled pill: the group draws a bottom border, and the indicator becomes a 2-pixel primary bar under the selected label. Use it when the row should read like section links on a settings page while still only changing a value. Leave variant out for the filled highlight.
Variant underline orientation vertical
The underline style also works in a column, with orientation set to vertical and variant set to underline. The border runs down the left edge and the indicator is a 2-pixel bar on it, beside the selected row. Use it for a settings sidebar that should look like a list of links, where a filled pill would be heavy in a tall stack.
FAQ
How do I control the selected Segment Group value in React?
Keep the selected string in state, pass it as value on SegmentGroup and update it in onValueChange. The callback receives an object, and the new string is details.value.
The group's value is the value of the checked SegmentGroupItem, as the Controlled demo shows. Set defaultValue instead when nothing else needs to know, and leave both out to start with no item picked and no highlight.
Should I use a Segment Group, Tabs or a Radio Group?
Use a segment group for a short, single choice that changes something in place, such as a list or grid view or a date range, with labels that fit on one row.
Tabs fit when each option has a panel of its own, since they tie each trigger to its panel for screen readers. A Radio Group is the better choice for a question in a form, or when an option needs a sentence of explanation beside it.
How do I submit a Segment Group value with a form?
Pass name to SegmentGroup, and the checked item's value is sent under that name with the rest of the form. The Form demo does this for a billing period and shows what the form sent. With a form library, set its field from onValueChange instead.
Every item renders a hidden radio input. Without a name, the inputs fall back to a generated one your server can't predict.
How do I stack a Segment Group vertically?
Set orientation to vertical on SegmentGroup. The items stack, each stretches to the group's width, and the highlight moves up and down with the selection, as in the Orientation vertical demo.
All four arrow keys keep working in a column, so nobody has to know which way the group runs. For the underline look in a column, add variant set to underline too.
How do I make a Segment Group look like underlined tabs?
Set variant to underline on SegmentGroup. A horizontal group draws a bottom border with a 2-pixel bar under the selected label, and a vertical one draws the border and the bar down its left edge, as the Variant underline demo shows.
The look changes, the behavior doesn't: it is still a radio group that holds one value. When each option should reveal its own content, use Tabs, whose line variant draws a similar bar.
How do I style the selected Segment Group item and its sliding indicator?
The selected item carries data-checked on every base, so a data-checked: class styles it and not-data-checked: the rest. SegmentGroup renders the indicator itself, so restyle the element whose data-slot is segment-group-indicator instead of adding one, as the Custom indicator demo does.
The indicator is placed with --left, --top, --width and --height, which Ark UI measures from the checked item, so keep the classes that read them. Ark UI also sets the transition inline, so change its speed with a --transition-duration variable on the indicator rather than a duration class.
How do I disable one option in a Segment Group?
Set disabled on that SegmentGroupItem. It dims, ignores clicks, and the arrow keys pass over it, as Security does in the Disabled item demo. A disabled item can't become the value through the interface, though your code can still set it.
To lock every option at once, set disabled on SegmentGroup. The selected item keeps its highlight, so people can still read the current choice.
Is the Ark UI Segment Group accessible with a keyboard?
Yes. The group is one stop in the tab order, landing on the checked item, and the arrow keys move to the next or previous item and select it in either orientation, looping at the ends. Space checks the focused item when it isn't checked yet.
A screen reader needs a name for the group as well, so pass aria-label to SegmentGroup. The Accessibility section lists every key.
API Reference
SegmentGroup
<div> data-slot="segment-group"
variant?SegmentGroupVariant
The visual variant of the segment group.
- Default
"default"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
data-variant?string
Mirrors variant.
SegmentGroupItem
<label> data-slot="segment-group-item"
valuestring
The item's value.
disabled?boolean
Whether the item is disabled.
invalid?boolean
Whether the item is invalid.
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
data-checked?string
Present when checked is set.
SegmentGroupItemText
<span> data-slot="segment-group-item-text"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
SegmentGroupIndicator
<div>
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
className?string
Merged with the part's classes.
--heightstring
The measured height, for animating open and closed.
--leftstring--topstring--widthstring
The measured width, for animating open and closed.
useSegmentGroup
variant?SegmentGroupVariant
The visual variant of the segment group.
- Default
"default"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.











