shadcn.io is not affiliated with official shadcn/ui
Radio Group examples · Standard
Radio Group with Descriptions for React
A radio group with a line of muted text under each option, so people see what a choice does before they pick it.
A one-word label does not always say what an option means. Here each density setting, Default, Comfortable and Compact, has a short sentence under its name in FieldDescription. Use it for settings where the choice has a consequence. In React, Base UI keeps the group and its labels connected.
Preview
Installation
FAQ
Which option starts selected?
defaultValue is comfortable, the second option. The item values are default, comfortable, and compact, from a list at the top of the file.
How does the description line up under the label?
Field: the item, then FieldContent with the FieldLabel above the FieldDescription.How is the description styled?
FieldDescription sets text-muted-foreground and text-sm. It is not wired to the item with aria-describedby, so a screen reader reads it as nearby text.
Does clicking the description select the option?
No. Only the name is the label, so clicking the name checks the item and the sentence under it does nothing. Each RadioGroupItem has an id, and FieldLabel points at it with htmlFor.
Related
- Basic Radio GroupA vertical radio group of three options
- Radio Group with CardsPlan options as bordered cards, where
- Radio Group with Custom ContentPricing tiers as selectable cards, each
- Radio Group in FormA required notification setting in a form
- Radio Group with IconsPayment method options with an icon
- Radio Group with Disabled StatesThree radio groups compared: all enabled