# Radio Group

> Accessible group of mutually exclusive radio controls with expressive spring dot animation and state layers.

Canonical URL: https://taut-ui.com/docs/components/radio-group

```tsx
import { Radio, RadioGroup } from "@/components/ui/radio-group";

export default function Particle() {
  return (
    <RadioGroup defaultValue="comfortable">
      <label className="flex cursor-pointer items-center gap-2.5 text-sm">
        <Radio value="compact" />
        <span>Compact</span>
      </label>
      <label className="flex cursor-pointer items-center gap-2.5 text-sm">
        <Radio value="comfortable" />
        <span>Comfortable</span>
      </label>
      <label className="flex cursor-pointer items-center gap-2.5 text-sm">
        <Radio value="spacious" />
        <span>Spacious</span>
      </label>
    </RadioGroup>
  );
}
```

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/radio-group.json
```

**Manual**

- Install the following dependencies:

```bash
npm install @base-ui/react
```

- Copy and paste the following code into your project.

```tsx title="components/ui/radio-group.tsx"
"use client";

import { Radio as RadioPrimitive } from "@base-ui/react/radio";
import { RadioGroup as RadioGroupPrimitive } from "@base-ui/react/radio-group";
import type React from "react";
import { cn } from "@/lib/utils";

export type RadioGroupProps = RadioGroupPrimitive.Props;

export function RadioGroup({
  className,
  ...props
}: RadioGroupPrimitive.Props): React.ReactElement {
  return (
    <RadioGroupPrimitive
      className={cn("flex flex-col items-start gap-2.5", className)}
      data-slot="radio-group"
      {...props}
    />
  );
}

export type RadioProps = RadioPrimitive.Root.Props;

export function Radio({
  className,
  ...props
}: RadioPrimitive.Root.Props): React.ReactElement {
  return (
    <RadioPrimitive.Root
      className={cn(
        "group/radio relative inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-full outline-none",
        "[--rb-on:var(--color-primary)] [--rb-rest:var(--color-muted-foreground)]",
        "inset-ring-(--rb-rest) inset-ring-2 data-checked:inset-ring-(--rb-on)",
        "not-aria-invalid:not-data-invalid:not-data-disabled:hover:[--rb-rest:var(--color-foreground)] not-aria-invalid:not-data-invalid:not-data-disabled:focus-visible:[--rb-rest:var(--color-foreground)] not-aria-invalid:not-data-invalid:not-data-disabled:active:[--rb-rest:var(--color-foreground)]",
        "aria-invalid:[--rb-on:var(--color-destructive)] aria-invalid:[--rb-rest:var(--color-destructive)] data-invalid:[--rb-on:var(--color-destructive)] data-invalid:[--rb-rest:var(--color-destructive)]",
        "data-disabled:pointer-events-none data-disabled:opacity-38 in-data-[slot=field-label]:data-disabled:opacity-100 in-data-[slot=label]:data-disabled:opacity-100 data-disabled:transition-none data-disabled:before:hidden data-disabled:[--rb-on:var(--color-foreground)] data-disabled:[--rb-rest:var(--color-foreground)]",
        "before:-translate-1/2 before:pointer-events-none before:absolute before:top-1/2 before:left-1/2 before:size-9 before:rounded-full before:bg-foreground before:opacity-0 before:transition-opacity before:duration-150 motion-reduce:before:transition-none",
        "aria-invalid:before:bg-(--rb-on) data-checked:before:bg-(--rb-on) data-invalid:before:bg-(--rb-on)",
        "not-data-disabled:hover:before:opacity-8 not-data-disabled:focus-visible:before:opacity-10 not-data-disabled:active:before:opacity-10",
        "in-[label:active]:not-data-disabled:before:opacity-10 in-[label:hover]:not-data-disabled:before:opacity-8",
        "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
        "pointer-coarse:after:-translate-1/2 pointer-coarse:after:absolute pointer-coarse:after:top-1/2 pointer-coarse:after:left-1/2 pointer-coarse:after:size-11",
        className,
      )}
      data-slot="radio"
      {...props}
    >
      <span
        aria-hidden="true"
        className="pointer-events-none size-2.5 scale-0 rounded-full bg-(--rb-on) [transition:scale_150ms_cubic-bezier(0.3,0,0.8,0.15)] group-data-checked/radio:scale-100 motion-reduce:transition-none group-data-checked/radio:[transition:scale_350ms_linear(0,0.5_8%,0.9_20%,1.02_34%,1_60%,1)]"
      />
    </RadioPrimitive.Root>
  );
}

export { RadioGroupPrimitive, RadioPrimitive, Radio as RadioGroupItem };
```

- Update the import paths to match your project setup.

## Usage [#usage]

```tsx
import { Radio, RadioGroup } from "@/components/ui/radio-group"
```

```tsx
<RadioGroup defaultValue="a">
  <label className="flex items-center gap-2.5 text-sm">
    <Radio value="a" />
    <span>Option A</span>
  </label>
  <label className="flex items-center gap-2.5 text-sm">
    <Radio value="b" />
    <span>Option B</span>
  </label>
</RadioGroup>
```

## Examples [#examples]

### With Descriptions [#with-descriptions]

```tsx
import { Radio, RadioGroup } from "@/components/ui/radio-group";

const plans = [
  {
    description: "Essential tools for personal projects.",
    label: "Starter",
    value: "starter",
  },
  {
    description: "Collaboration and analytics for growing teams.",
    label: "Pro",
    value: "pro",
  },
  {
    description: "Custom limits, SSO, and dedicated support.",
    label: "Enterprise",
    value: "enterprise",
  },
];

export default function Particle() {
  return (
    <RadioGroup className="w-full max-w-xs gap-3.5" defaultValue="pro">
      {plans.map((plan) => (
        <label
          className="flex cursor-pointer items-start gap-3"
          key={plan.value}
        >
          <Radio className="mt-0.5" value={plan.value} />
          <span className="flex flex-col gap-0.5">
            <span className="font-medium text-foreground text-sm leading-5">
              {plan.label}
            </span>
            <span className="text-muted-foreground text-xs leading-4">
              {plan.description}
            </span>
          </span>
        </label>
      ))}
    </RadioGroup>
  );
}
```

### Card Selection [#card-selection]

```tsx
import {
  Card,
  CardAction,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card";
import { Radio, RadioGroup } from "@/components/ui/radio-group";

const options = [
  {
    description: "Delivered in 3–5 business days",
    label: "Standard shipping",
    price: "Free",
    value: "standard",
  },
  {
    description: "Delivered in 1–2 business days",
    label: "Express shipping",
    price: "$12",
    value: "express",
  },
];

export default function Particle() {
  return (
    <RadioGroup className="w-full max-w-sm gap-2.5" defaultValue="standard">
      {options.map((option) => (
        <Card
          className="w-full cursor-pointer rounded-2xl has-data-checked:bg-[color-mix(in_oklab,var(--color-card),var(--color-primary)_14%)] has-data-checked:shadow-[inset_0_0_0_0.0625rem_var(--color-primary)]"
          key={option.value}
          orientation="horizontal"
          render={<label />}
          ripple
        >
          <Radio value={option.value} />
          <CardHeader className="gap-0.5">
            <CardTitle className="text-sm leading-5">{option.label}</CardTitle>
            <CardDescription className="text-xs leading-4">
              {option.description}
            </CardDescription>
            <CardAction className="font-medium text-foreground text-sm tabular-nums">
              {option.price}
            </CardAction>
          </CardHeader>
        </Card>
      ))}
    </RadioGroup>
  );
}
```

### Disabled [#disabled]

```tsx
import { Radio, RadioGroup } from "@/components/ui/radio-group";

export default function Particle() {
  return (
    <RadioGroup defaultValue="email" disabled>
      <label className="flex cursor-not-allowed items-center gap-2.5 text-muted-foreground text-sm">
        <Radio value="email" />
        <span>Email notifications</span>
      </label>
      <label className="flex cursor-not-allowed items-center gap-2.5 text-muted-foreground text-sm">
        <Radio value="sms" />
        <span>SMS notifications</span>
      </label>
    </RadioGroup>
  );
}
```

## API Reference [#api-reference]

### RadioGroup [#radiogroup]

Wraps Base UI `RadioGroup`.

| Prop            | Type                                   | Default | Description                                        |
| --------------- | -------------------------------------- | ------- | -------------------------------------------------- |
| `value`         | `Value`                                | -       | Controlled selected value                          |
| `defaultValue`  | `Value`                                | -       | Initial uncontrolled selected value                |
| `onValueChange` | `(value: Value, eventDetails) => void` | -       | Callback fired when the selected option changes    |
| `name`          | `string`                               | -       | Field name submitted with a form                   |
| `disabled`      | `boolean`                              | `false` | Disables all radio buttons in the group            |
| `readOnly`      | `boolean`                              | `false` | Prevents changing the current selection            |
| `required`      | `boolean`                              | `false` | Marks the group as required for form submission    |

### Radio [#radio]

Wraps Base UI `Radio.Root` (`RadioGroupItem` is also exported as an alias).

| Prop       | Type      | Default | Description                                |
| ---------- | --------- | ------- | ------------------------------------------ |
| `value`    | `Value`   | -       | Unique value represented by this radio     |
| `disabled` | `boolean` | `false` | Disables interaction for this radio button |
| `readOnly` | `boolean` | `false` | Prevents changing this radio button        |
