shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A radio group shows every option at once and lets people pick exactly one, and picking another clears the first. It suits a short list where seeing the choices side by side helps the decision, such as a shipping speed, a billing period or a layout density.
For a long list, a Select takes less room. When more than one option can be on at the same time, use a Checkbox for each.
Installation
Anatomy

Usage
import { FieldLabel } from "@/components/ui/field";
import {
RadioGroup, RadioGroupItem,
} from "@/components/ui/radio-group";const RadioGroupDemo = () => (
<RadioGroup className="w-fit" defaultValue="comfortable">
<div className="flex items-center gap-3">
<RadioGroupItem id="r1" value="default" />
<FieldLabel htmlFor="r1">Default</FieldLabel>
</div>
<div className="flex items-center gap-3">
<RadioGroupItem id="r2" value="comfortable" />
<FieldLabel htmlFor="r2">Comfortable</FieldLabel>
</div>
<div className="flex items-center gap-3">
<RadioGroupItem id="r3" value="compact" />
<FieldLabel htmlFor="r3">Compact</FieldLabel>
</div>
</RadioGroup>
);Accessibility
RadioGroup has the radiogroup role, and each RadioGroupItem is an element with the radio role and aria-checked. Only one option at a time is in the tab order. Each option needs a name, from a FieldLabel whose htmlFor matches its id, and the group needs one too, from a FieldSet and FieldLegend around it or aria-label on it.
- Tab
- Moves focus to the checked item, or to the first item when none is checked.
- Space
- When focus is on an unchecked item, checks it.
- Arrow Down
- Moves focus to the next item and checks it, skipping disabled items, from the last back to the first.
- Arrow Right
- Moves focus to the next item and checks it, skipping disabled items, from the last back to the first.
- Arrow Up
- Moves focus to the previous item and checks it, skipping disabled items, from the first to the last.
- Arrow Left
- Moves focus to the previous item and checks it, skipping disabled items, from the first to the last.
- Enter
- Submits the form the group is in.
Demos
Description
Three density settings, Default, Comfortable and Compact, each with a short line under its name that says what it changes, and Comfortable picked to start. Each radio sits in a horizontal Field, with its name and that line stacked in a FieldContent beside it. Add the line when the names alone don't say what happens, and leave it off when it would only repeat the label.
Choice card
Three plans, Plus, Pro and Enterprise, drawn as cards with a title, a line on who each is for, and the radio at the end of the row. A FieldLabel wraps each card's Field, so a click anywhere on the card picks that plan. Use cards when each option is a decision of its own, like a pricing tier, and plain rows when the options are single words.
Fieldset
A Subscription Plan question with three answers, monthly at $9.99, yearly at $99.99 and lifetime at $299.99, and a note that the longer plans cost less. FieldSet and FieldLegend render a real fieldset and legend, so a screen reader names the group as focus enters it. Use one whenever the question isn't already written as a heading right above the options.
Horizontal
Three short options, Option 1 to Option 3, side by side in one row that wraps when the space runs out. flex classes on RadioGroup replace its one-column grid, and nothing else changes. Use a row for two to four one-word answers, such as a billing period, and stack anything longer.
Disabled
Three options where the first, labeled Disabled, can't be picked, and Option 2 is selected to start. That item gets disabled, which fades its circle, and data-disabled on its Field fades its label. Disable one option when it exists but isn't available right now, such as a sold-out size, and say why next to it.
Invalid
Notification preferences, Email only, SMS only or both, drawn in their error state under a legend and a description. The demo sets aria-invalid on each RadioGroupItem, which draws the circles red, and data-invalid on each Field, which turns the labels red. Show it after a failed submit, together with a message that says what has to change.
RTL
The density options in Arabic, each with its description, with dir set to rtl. The radios sit at the right edge with their text to the left of them, and nothing in the markup changes apart from the direction. Set it on the group or a wrapper when the form reads right to left inside a page that doesn't.
FAQ
How do I control the selected Radio Group value in React?
Pass value and update it in onValueChange, whose first argument is the picked item's value. Use defaultValue instead when the group can keep its own state.
The group's value is the value of whichever RadioGroupItem is picked. Hold it in state when another part of the page depends on it, such as a price that changes with the plan.
How do I submit a Radio Group with a form?
Set name on RadioGroup. The form then receives that name with the picked item's value, not its visible label, and receives nothing at all while no option is picked.
Add required when an answer is mandatory, which also marks the group with aria-required. Each option has a radio input behind it, so a FormData built from the form reads the answer like any other field.
Why is my Radio Group label not clickable?
Because nothing connects it to the item. RadioGroupItem is the circle alone and drops any text inside it, so give each item an id and put a FieldLabel beside it with htmlFor set to that id, as the demos do. A click on the words then picks the option, and a screen reader reads them as its name.
For a whole card that picks its option, wrap the card in the label, as the Choice card demo does.
How does keyboard navigation work in a Radio Group?
The group is a single stop in the tab order. Tab lands on the checked option, or on the first one when nothing is checked yet, and the arrow keys move to the next or previous option and pick it as they go. Space picks the focused option if it isn't picked already.
Up and Left go back, Down and Right go forward, and the movement wraps from the last option to the first. There are no Home or End shortcuts.
How do I show a Radio Group as invalid with UI SDK?
Set aria-invalid on each RadioGroupItem and data-invalid on the Field around each, as the Invalid demo does. The circles turn red, a screen reader hears each option as invalid, and the labels take the error color.
Color isn't the message, though. Put a sentence that says what's wrong under the options, in a FieldError or the fieldset's description.
How do I disable a Radio Group or one of its options?
Set disabled on RadioGroup to lock every option, or on one RadioGroupItem to lock only that one, as the Disabled demo does. A disabled option stays visible and can't be picked.
For an answer people should see but not change, such as a plan an admin has locked, use readOnly instead, which keeps the options at full strength and still submits the answer.
How do I lay out Radio Group options in a row?
RadioGroup lays its items out as a grid with one column. Add a class to it, such as grid-cols-3 for three equal columns, or flex with a gap for a row that sizes to its labels, as the Horizontal demo does.
UI SDK's group has no orientation setting, and all four arrow keys move in either layout.
Should I use a Radio Group, a Select or a Segment Group?
Use a radio group when there are a handful of options and people should read them all before choosing, especially when an option needs a description or its own card.
A Select suits a long list, or a short one where space is tight and the options are familiar, like a country. A Segment Group is a compact row of short labels with a sliding indicator, which fits a view switcher better than a form question. If several options can be on at once, use a Checkbox for each.
API Reference
RadioGroup
<div> data-slot="radio-group"
value?T | null
The checked radio's value. Pass it to control the group. null checks nothing.
- Type
T | null
defaultValue?T | null
The radio checked at first, when uncontrolled. A form reset returns to it.
- Type
T | null
onValueChange?(value: string, details: RadioGroupChangeDetails) → void
Runs when the selection changes. A cleared selection, as a form reset to
no value gives, reports "", which selects nothing when passed back.
- Type
(value: string, details: RadioGroupChangeDetails) → void- Parameters
value– stringdetails– RadioGroupChangeDetails- Returns
void
controller?{ getValue: () → T | null; setValue: (value: T | null, details?: Details) → boolean; focus: () → void; }
Checks radios from anywhere. Create one with createRadioGroupController().
- Type
{ getValue: () → T | null; setValue: (value: T | null, details?: Details) → boolean; focus: () → void; }
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Disables every radio like native ones: they can't be focused or changed, and the value isn't submitted.
form?string
The id of a form to belong to, when the group isn't inside that form.
loop?boolean
Whether arrow keys wrap from the last item to the first.
- Default
true
name?string
The name the value submits under. Without one, the group submits nothing.
readOnly?boolean
Keeps the items focusable and the value submitted, but stops changes.
required?boolean
Blocks form submission until an item is checked, with the browser's own message.
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
data-disabled?string
Present when disabled, by its own prop, the group or a <fieldset>.
data-readonly?string
Present when the group is read-only.
data-required?string
Present when the group is required.
RadioGroupText
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
RadioGroupLabel
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
RadioGroupItem
<button> data-slot="radio"
valuestring
What the group's value becomes when this item is checked.
disabled?boolean
Skips the item, like a disabled native radio: arrow keys pass it and it can't be focused or checked.
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
data-checked?string
Present on the checked radio.
data-disabled?string
Present when disabled, by its own prop, the group or a <fieldset>.
data-readonly?string
Present when the group is read-only.
data-required?string
Present when the group is required.
data-unchecked?string
Present on radios that aren't checked.











