Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Radio Group for Radix UI

Radio buttons for React on Radix UI: every option stays on screen, picking one clears the others, and the arrow keys move the choice.

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.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Radio Group anatomy: root, label, item control, indicator, item, item text

Usage

import {
  RadioGroup, RadioGroupItem,
} from "@/components/ui/radio-group";
<RadioGroup className="w-fit" defaultValue="comfortable">
  <RadioGroupItem value="default">Default</RadioGroupItem>
  <RadioGroupItem value="comfortable">Comfortable</RadioGroupItem>
  <RadioGroupItem value="compact">Compact</RadioGroupItem>
</RadioGroup>

With Radix UI, RadioGroupItem is the circle alone and isn't built to hold its text. Give each item an id and put a FieldLabel beside it with htmlFor set to that id, as the demos below do.

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, from the last back to the first.
Arrow Right
Moves focus to the next item and checks it, from the last back to the first.
Arrow Up
Moves focus to the previous item and checks it, from the first to the last.
Arrow Left
Moves focus to the previous item and checks it, from the first to the last.
Home
Moves focus to the first item without checking it.
End
Moves focus to the last item without checking it.

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.

Preview width

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.

Preview width

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.

Preview width

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 orientation set to horizontal tells assistive technology about the row. Use a row for two to four one-word answers, such as a billing period, and stack anything longer.

Preview width

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.

Preview width

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.

Preview width

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.

Preview width

FAQ

How do I control the selected Radio Group value in React?

Pass value and update it in onValueChange, which receives the picked item's value as a string. 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. Radix UI renders its hidden inputs only when the group sits inside a <form> element, so keep it in one.

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.

The movement wraps from the last option to the first. Home and End jump to the first and last option without picking them, and with orientation set, only the arrows along that axis move.

How do I show a Radio Group as invalid with Radix UI?

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.

Radix UI has no read-only mode, so an answer people should see but not change is a disabled group, or plain text.

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.

Set orientation to horizontal as well. Radix UI reports it through aria-orientation and then moves with Left and Right only.

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"

PropType
value?string | null

The value. Pair with onValueChange to control it.

Type
string | null
defaultValue?string

The value it starts with, when you don't control value.

onValueChange?(value: string) → void

Called when the value changes.

Parameters

value – string

Returns
void
dir?Direction

The reading direction. Inherits the nearest DirectionProvider when unset.

disabled?boolean

Whether it's disabled.

form?string

The id of the form it submits with, when it isn't inside one.

loop?boolean

Whether arrow keys wrap from the last item to the first and back.

name?string

The name it submits with its form.

orientation?Orientation

Horizontal or vertical: which arrow keys move between items.

required?boolean

Whether a value is required to submit its form.

asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when groupDisabled is true.

data-invalid?string

Present when groupInvalid is true.

data-orientationRovingFocusGroupProps["orientation"]

Mirrors the orientation prop.

Type
RovingFocusGroupProps["orientation"]
data-required?string

Present when required is true.

RadioGroupItem

<label> data-slot="radio-group-item"

PropType
valuestring

The item's value.

asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

RadioGroupIndicator

<div> data-slot="radio-group-indicator"

AttributeType
data-disabled?string

Present when groupDisabled is true.

data-orientationRovingFocusGroupProps["orientation"]

Mirrors the orientation prop.

Type
RovingFocusGroupProps["orientation"]
CSS variableType
--heightstring

The measured height, for animating open and closed.

--leftstring
--topstring
--transition-propertystring
--widthstring

The measured width, for animating open and closed.

RadioGroupText

data-slot="radio-group-item-text"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

AttributeType
data-disabled?string

Present when groupDisabled is true.

data-invalid?string

Present when groupInvalid is true.

data-orientationRovingFocusGroupProps["orientation"]

Mirrors the orientation prop.

Type
RovingFocusGroupProps["orientation"]
data-required?string

Present when required is true.

RadioGroupLabel

data-slot="radio-group-label"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

AttributeType
data-disabled?string

Present when groupDisabled is true.

data-invalid?string

Present when groupInvalid is true.

data-orientationRovingFocusGroupProps["orientation"]

Mirrors the orientation prop.

Type
RovingFocusGroupProps["orientation"]
data-required?string

Present when required is true.