Command Palette

Search for a command to run...

Radio Group

A set of checkable buttons where only one can be checked at a time.

Installation

npm i @radix-ui/react-radio-group

Usage

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import { Label } from "@/components/ui/label" import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group" export function RadioGroupDemo() { return ( <RadioGroup defaultValue="comfortable"> <div className="flex items-center space-x-2"> <RadioGroupItem value="default" id="r1" /> <Label htmlFor="r1">Default</Label> </div> <div className="flex items-center space-x-2"> <RadioGroupItem value="comfortable" id="r2" /> <Label htmlFor="r2">Comfortable</Label> </div> <div className="flex items-center space-x-2"> <RadioGroupItem value="compact" id="r3" /> <Label htmlFor="r3">Compact</Label> </div> </RadioGroup> ) }

Examples

Disabled

Disabled Group

Disabled Item

Custom Sizes

Small

Default (Medium)

Large

Custom Layout

Horizontal Layout

Props

ComponentPropsDescription
RadioGroupRadioGroupPrimitive.RadioGroupProps
defaultValue?: string
value?: string
onValueChange?: (value: string) => void
disabled?: boolean
The root component for the radio group.
RadioGroupItemRadioGroupPrimitive.RadioGroupItemProps
value: string
disabled?: boolean
required?: boolean
id?: string
An individual radio item within the group.

Accessibility

The Radio Group component adheres to the WAI-ARIA Radio Group Pattern.

KeyDescription
TabMoves focus to the radio group.
SpaceWhen focus is on an unchecked radio item, checks it.
Arrow Down/RightMoves focus to the next radio item in the group.
Arrow Up/LeftMoves focus to the previous radio item in the group.