---
title: Radio Group
description: Provides shared state to a series of radio buttons.
links:
  doc: https://base-ui.com/react/components/radio-group
  anatomy: https://base-ui.com/react/components/radio-group#anatomy
  api: https://base-ui.com/react/components/radio-group#api-reference
---

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

export function RadioGroupDemo() {
  return (
    <RadioGroup aria-labelledby="framework-label" defaultValue="next">
      <div id="framework-label" className="font-medium text-sm">
        Select your framework
      </div>
      <Label>
        <Radio value="next" /> Next.js
      </Label>
      <Label>
        <Radio value="vite" /> Vite
      </Label>
      <Label>
        <Radio value="astro" /> Astro
      </Label>
    </RadioGroup>
  );
}
```

## Installation

<CodeTabs>

<TabsList>
  <TabsTab value="cli">CLI</TabsTab>
  <TabsTab value="manual">Manual</TabsTab>
</TabsList>
<TabsPanel value="cli">

```bash
npx @zbmui/cli@latest add radio-group
```

</TabsPanel>
<TabsPanel value="manual">

<Steps>

<Step>Install the following dependencies:</Step>

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

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="radio-group" title="components/ui/radio-group.tsx" />

<Step>Update the import paths to match your project setup.</Step>

</Steps>
</TabsPanel>

</CodeTabs>

## Usage

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

```tsx
<RadioGroup defaultValue="next">
  <Label>
    <Radio value="next" /> Next.js
  </Label>
  <Label>
    <Radio value="vite" /> Vite
  </Label>
  <Label>
    <Radio value="astro" /> Astro
  </Label>
</RadioGroup>
```

## Examples

### Labeling a radio group

Label the group with `aria-labelledby` and a sibling label element:

```tsx
<div id="storage-type-label">Storage type</div>
<RadioGroup aria-labelledby="storage-type-label">{/* ... */}</RadioGroup>
```

An enclosing `<label>` is the simplest labeling pattern for each radio:

```tsx
<label>
  <Radio value="ssd" />
  SSD
</label>
```

### Disabled

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

export function RadioGroupDemo() {
  return (
    <RadioGroup aria-label="Framework" defaultValue="next">
      <Label>
        <Radio value="next" /> Next.js
      </Label>
      <Label>
        <Radio disabled value="vite" /> Vite (disabled)
      </Label>
      <Label>
        <Radio value="astro" /> Astro
      </Label>
    </RadioGroup>
  );
}
```

### Description

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

export function RadioGroupDemo() {
  return (
    <RadioGroup aria-labelledby="subscription-plan" defaultValue="free">
      <div id="subscription-plan">Choose a subscription plan</div>
      <div className="flex items-start gap-2">
        <Radio id="free" value="free" />
        <div className="flex flex-col gap-1">
          <Label htmlFor="free">Free</Label>
          <p className="text-muted-foreground text-xs">Basic features for personal use.</p>
        </div>
      </div>
      <div className="flex items-start gap-2">
        <Radio id="pro" value="pro" />
        <div className="flex flex-col gap-1">
          <Label htmlFor="pro">Pro</Label>
          <p className="text-muted-foreground text-xs">Advanced tools for professionals.</p>
        </div>
      </div>
    </RadioGroup>
  );
}
```

### Card style

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

export function RadioGroupDemo() {
  return (
    <RadioGroup aria-label="Notification method" defaultValue="email">
      <Label className="flex items-start gap-2 rounded-lg border p-3 hover:bg-accent/50 has-data-checked:border-primary/48 has-data-checked:bg-accent/50">
        <Radio value="email" />
        <div className="flex flex-col gap-1">
          <p>Email</p>
          <p className="text-muted-foreground text-xs">Receive notifications via email.</p>
        </div>
      </Label>
      <Label className="flex items-start gap-2 rounded-lg border p-3 hover:bg-accent/50 has-data-checked:border-primary/48 has-data-checked:bg-accent/50">
        <Radio value="sms" />
        <div className="flex flex-col gap-1">
          <p>SMS</p>
          <p className="text-muted-foreground text-xs">Receive notifications via text message.</p>
        </div>
      </Label>
    </RadioGroup>
  );
}
```
