Skip to content
All components
Forms

Radio group

Choose exactly one option from a small visible set of mutually exclusive choices.

One choice from a set.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add radio-group

Then import it from @/components/ui/radio-group. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Billing period

Choose one billing period from a short list, with one unavailable option. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

export function RadioGroupBillingPeriod() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <RadioGroup aria-label="Billing period" defaultValue="monthly" className="flex flex-col gap-3">
        <div className="flex items-center gap-2">
          <RadioGroupItem value="monthly" id="radio-demo-monthly" />
          <Label htmlFor="radio-demo-monthly">Monthly</Label>
        </div>
        <div className="flex items-center gap-2">
          <RadioGroupItem value="yearly" id="radio-demo-yearly" />
          <Label htmlFor="radio-demo-yearly">Yearly, two months free</Label>
        </div>
        <div className="flex items-center gap-2">
          <RadioGroupItem value="custom" id="radio-demo-custom" disabled />
          <Label htmlFor="radio-demo-custom">Custom, contact sales</Label>
        </div>
      </RadioGroup>
    </div>
  )
}

With descriptions

Give each option a supporting description associated with its radio. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

const shippingOptions = [
  { value: "standard", label: "Standard", hint: "4 to 6 business days. Free." },
  { value: "express", label: "Express", hint: "2 business days. $9.00." },
  { value: "pickup", label: "Pick up in store", hint: "Ready tomorrow after 2 pm." },
]

export function RadioGroupWithDescriptions() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <p id={`${id}-shipping`} className="text-label-md text-strong-950">Shipping speed</p>
        <RadioGroup aria-labelledby={`${id}-shipping`} defaultValue="standard">
          {shippingOptions.map((option) => (
            <div key={option.value} className="flex items-start gap-2">
              <RadioGroupItem
                value={option.value}
                id={`${id}-${option.value}`}
                className="mt-0.5"
                aria-describedby={`${id}-${option.value}-hint`}
              />
              <div className="flex flex-col gap-1">
                <Label htmlFor={`${id}-${option.value}`}>{option.label}</Label>
                <p id={`${id}-${option.value}-hint`} className="text-paragraph-sm text-sub-600">
                  {option.hint}
                </p>
              </div>
            </div>
          ))}
        </RadioGroup>
      </div>
    </div>
  )
}

Invalid

Connect radio-group validation feedback to the actual choices. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { FieldError } from "@/components/ui/field"
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

export function RadioGroupInvalid() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <p id={`${id}-size`} className="text-label-md text-strong-950">Team size</p>
        <RadioGroup
          aria-labelledby={`${id}-size`}
          aria-describedby={`${id}-size-error`}
          aria-invalid
          required
        >
          {["Just me", "2 to 10", "More than 10"].map((label, index) => (
            <div key={label} className="flex items-center gap-2">
              <RadioGroupItem value={String(index)} id={`${id}-size-${index}`} aria-invalid />
              <Label htmlFor={`${id}-size-${index}`}>{label}</Label>
            </div>
          ))}
        </RadioGroup>
        <FieldError id={`${id}-size-error`}>Choose a team size to see the right plan.</FieldError>
      </div>
    </div>
  )
}

Horizontal

Lay a short set of options in a wrapping row with horizontal arrow-key movement. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

export function RadioGroupHorizontal() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <p id={`${id}-view`} className="text-label-md text-strong-950">Default view</p>
        <RadioGroup
          aria-labelledby={`${id}-view`}
          orientation="horizontal"
          defaultValue="list"
          className="flex flex-wrap gap-x-6 gap-y-3"
        >
          {["List", "Board", "Calendar"].map((label) => (
            <div key={label} className="flex items-center gap-2">
              <RadioGroupItem value={label.toLowerCase()} id={`${id}-view-${label}`} />
              <Label htmlFor={`${id}-view-${label}`}>{label}</Label>
            </div>
          ))}
        </RadioGroup>
      </div>
    </div>
  )
}

Disabled

Inspect the unavailable control using its real disabled semantics. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

export function RadioGroupDisabled() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <p id={`${id}-region`} className="text-label-md text-strong-950">Data region</p>
        <RadioGroup aria-labelledby={`${id}-region`} aria-describedby={`${id}-region-hint`} defaultValue="eu" disabled>
          {[["us", "United States"], ["eu", "European Union"]].map(([value, label]) => (
            <div key={value} className="flex items-center gap-2">
              <RadioGroupItem value={value} id={`${id}-region-${value}`} />
              <Label htmlFor={`${id}-region-${value}`}>{label}</Label>
            </div>
          ))}
        </RadioGroup>
        <p id={`${id}-region-hint`} className="text-paragraph-sm text-sub-600">
          The region is fixed after the workspace is created.
        </p>
      </div>
    </div>
  )
}

Sizes

Compare the sm and md radio sizes. Both sizes keep a 24px pointer target around the visible circle.

"use client"

import * as React from "react"

import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

export function RadioGroupSizes() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <p id={`${id}-density`} className="text-label-md text-strong-950">Row density</p>
        <RadioGroup aria-labelledby={`${id}-density`} defaultValue="compact" className="flex flex-col gap-3">
          <div className="flex items-center gap-2">
            <RadioGroupItem size="sm" value="compact" id={`${id}-density-compact`} />
            <Label htmlFor={`${id}-density-compact`} className="text-label-xs">
              Compact, small control
            </Label>
          </div>
          <div className="flex items-center gap-2">
            <RadioGroupItem value="comfortable" id={`${id}-density-comfortable`} />
            <Label htmlFor={`${id}-density-comfortable`}>Comfortable, medium control</Label>
          </div>
        </RadioGroup>
      </div>
    </div>
  )
}

Radio cards

Present each option as a selectable card. Each card is a label for its radio, so the whole card selects it. Arrow keys still move between options and the checked card is outlined.

"use client"

import * as React from "react"

import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

const plans = [
  { value: "starter", label: "Starter", price: "$0 per month", hint: "Up to 3 projects and 1 GB of storage." },
  { value: "team", label: "Team", price: "$12 per seat", hint: "Unlimited projects, shared workspaces." },
  { value: "business", label: "Business", price: "$24 per seat", hint: "SSO, audit log and priority support." },
]

export function RadioGroupRadioCards() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <p id={`${id}-plan`} className="text-label-md text-strong-950">Plan</p>
        <RadioGroup aria-labelledby={`${id}-plan`} defaultValue="team" className="flex flex-col gap-3">
          {plans.map((plan) => (
            <label
              key={plan.value}
              htmlFor={`${id}-plan-${plan.value}`}
              className="flex cursor-pointer items-start gap-3 rounded-12 border border-soft-200 bg-white-0 p-4 transition-colors duration-200 hover:border-sub-300 has-data-[state=checked]:border-primary-base has-data-[state=checked]:bg-primary-alpha-10 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-primary-base motion-reduce:transition-none"
            >
              <RadioGroupItem
                value={plan.value}
                id={`${id}-plan-${plan.value}`}
                className="mt-0.5"
                aria-labelledby={`${id}-plan-${plan.value}-name ${id}-plan-${plan.value}-price`}
                aria-describedby={`${id}-plan-${plan.value}-hint`}
              />
              <span className="flex min-w-0 flex-1 flex-col gap-1">
                <span className="flex flex-wrap items-baseline justify-between gap-x-3">
                  <span id={`${id}-plan-${plan.value}-name`} className="text-label-sm text-strong-950">
                    {plan.label}
                  </span>
                  <span id={`${id}-plan-${plan.value}-price`} className="text-paragraph-sm text-sub-600">
                    {plan.price}
                  </span>
                </span>
                <span id={`${id}-plan-${plan.value}-hint`} className="text-paragraph-sm text-sub-600">
                  {plan.hint}
                </span>
              </span>
            </label>
          ))}
        </RadioGroup>
      </div>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

RadioGroup

Choose one value from a visible set of mutually exclusive options.

RadioGroup props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (23)
RadioGroup inherited props
PropTypeDefaultDescription
namestring | undefined—Name used by the control's form submission or primitive form integration.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
requiredboolean | undefined—Mark this control as required using its native or primitive semantics. Consumers own contextual validation feedback.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
dir("ltr" | "rtl") | undefined—Reading direction used by the primitive. Keep it consistent with the surrounding content and Direction provider.
orientation("horizontal" | "vertical") | undefined—Horizontal or vertical layout/navigation axis as defined by this primitive.
loopboolean | undefined—Allow keyboard navigation to wrap between the first and last eligible items.
defaultValuestring | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
valuestring | null | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
onValueChange((value: string) => void) | undefined—Receive the next value in the source-defined shape. A controlled parent must apply it to value.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

RadioGroupItem

One item within its parent composition. Keep parent context and the value, label or state required by the source API.

RadioGroupItem props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
size"sm" | "md" | undefined"md"Circle size: sm (16px) or md (20px). Both keep a 24px pointer target. Defaults to md.
Inherited props (20)
RadioGroupItem inherited props
PropTypeDefaultDescription
value(required)string—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLButtonElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLButtonElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLButtonElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLButtonElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
type"button" | "submit" | "reset" | undefined—Native element or primitive mode defined by the source union. Choose a supported value; its meaning depends on the component.
checkedboolean | undefined—Current checked state. Apply the requested value from onCheckedChange when the parent owns this state.
requiredboolean | undefined—Mark this control as required using its native or primitive semantics. Consumers own contextual validation feedback.
refReact.Ref<HTMLButtonElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

Accessibility & usage

From registry/ui/radio-group.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Two to about seven options that people should compare side by side before choosing.
  • Choices that benefit from a description under each option, such as plans or shipping speeds.
  • A required choice with no sensible default, shown with no option selected.

When not to use

  • Long lists, or lists people search by name.
  • Independent options where several can be selected.
  • A single on/off setting.

Anatomy

RadioGroup
The Radix radio group root (role=radiogroup). Owns value, defaultValue, onValueChange, orientation, disabled, required and name.
RadioGroupItem
One radio button with a value; aria-invalid shows the error border. size is sm (16px) or md (20px, default); both keep a 24px pointer target.
Label
A Label with htmlFor matching each item id.
Group name
A visible heading or legend referenced from the group's aria-labelledby, or an aria-label.
Radio card (composition)
A label element around a RadioGroupItem and its text, styled with has-data-[state=checked] to outline the selected card. The whole card selects the option; arrow keys still move between items.

Keyboard & interaction

  • Tab moves into the group, onto the selected option (or the first one), and Tab again leaves the group.
  • Arrow keys move focus and select the next or previous option, wrapping at the ends; orientation limits which arrows apply.
  • Space selects the focused option when nothing is selected yet.
  • Disabled items are skipped by arrow keys; a disabled group leaves the Tab order.
  • For an invalid group, set aria-invalid and aria-describedby on the group to the error, and aria-invalid on items for the error border.

Responsive behavior

  • Stack options vertically by default; a wrapping row (flex-wrap) suits only short labels.
  • Items look 20 CSS px but each has a 24x24 CSS px hit area (WCAG 2.5.8); associated labels enlarge the target further. Keep the hit area if you resize the items.
  • Descriptions sit under each label and wrap; align the radio with the first line of the label.

Content guidelines

  • Label each option with the choice itself ('Express'), and put cost or timing in a description.
  • Order options logically: by size, price, frequency, or most common first.
  • Error: ask for the missing choice ('Choose a team size to see the right plan').
  • Group heading: a short question or noun ('Shipping speed').

Alternatives

  • Select — A longer list where space is limited.
  • Native select — A long list on phones with the platform picker.
  • Checkbox — Independent options, any number selected.
  • Switch — A single on/off setting that applies immediately.
  • Toggle group — A compact single-choice control for view or formatting options.

Resources