---
title: "Radio Group · UI SDK — StyleX Blocks"
description: "Single-choice option lists with outline, subtle, and solid radio controls."
url: "https://stylexblocks.com/components/ui-sdk/radio-group/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Radio Group

Single-choice option lists with outline, subtle, and solid radio controls.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/radio-group.md), [Base UI](https://stylexblocks.com/components/base-ui/radio-group.md)
- Category: Form
- Variants: outline, subtle, solid
- Sizes: xs, sm, md, lg
- Used in blocks: [Contact Form](https://stylexblocks.com/block/ui-sdk/contact-form.md), [Form Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard.md), [Theme Showcase](https://stylexblocks.com/block/ui-sdk/theme-showcase.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/radio-group/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add radio-group
```

Equivalent: `npx shadcn add @stylexblocks/radio-group`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/radio-group.json

## Usage

```tsx
import { RadioGroup } from "#components/ui/ui-sdk/radio-group.tsx";
import { indigoPalette } from "@stylexblocks/ui/themes/palettes.ts";

export function Example() {
  return (
    // Item is a label wrapper; ItemControl is UI SDK's Radio and takes the
    // value — arrow keys and roving focus come from UI SDK's radio group
    <RadioGroup.Root defaultValue="growth" variant="solid" size="md" palette={indigoPalette} aria-label="Plan">
      <RadioGroup.Item>
        <RadioGroup.ItemControl value="growth" />
        <RadioGroup.ItemText>Growth</RadioGroup.ItemText>
      </RadioGroup.Item>
    </RadioGroup.Root>
  );
}

// controlled: <RadioGroup.Root value={plan} onValueChange={setPlan}>
```

## Source

`components/ui/ui-sdk/radio-group.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import {
  Radio as UiSdkRadio,
  RadioGroup as UiSdkRadioGroup,
  RadioIndicator as UiSdkRadioIndicator,
} from "@ui-sdk/react/radio";
import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";
import { defineSlotRecipe, resolveSlotStyles } from "#lib/recipe-props.ts";
import { radioGroupItemControlDotVars } from '@stylexblocks/ui/slot-recipes/radio-group.stylex.ts'

import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { colors } from '@stylexblocks/ui/tokens/colors.stylex.ts'
import { cursor } from '@stylexblocks/ui/tokens/cursor.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { radii } from '@stylexblocks/ui/tokens/radii.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'


const radioGroupItem = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    position: 'relative',
    fontWeight: fontWeights.medium,
    cursor: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': cursor.disabled,
    },
  },
})

const radioGroupItemSizes = stylex.create({
  xs: {
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    gap: spacing._1_5,
  },
  sm: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    gap: spacing._2,
  },
  md: {
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    gap: spacing._2_5,
  },
  lg: {
    fontSize: fontSizes.md,
    lineHeight: lineHeights.md,
    gap: spacing._3,
  },
})

const radioGroupItemControl = stylex.create({
  base: {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    flexShrink: 0,
    verticalAlign: 'top',
    color: colors.white,
    borderWidth: '1px',
    borderColor: {
      default: 'transparent',
      ':is([data-invalid], [aria-invalid="true"])':
        semanticColors.borderDestructive,
    },
    borderRadius: radii.full,
    cursor: {
      default: cursor.radio,
      ':is(:disabled, [disabled], [data-disabled])': cursor.disabled,
    },
    outlineWidth: {
      default: null,
      ':focus-visible': '1px',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '2px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    [radioGroupItemControlDotVars.height]: '100%',
    [radioGroupItemControlDotVars.width]: '100%',
    [radioGroupItemControlDotVars.borderRadius]: radii.full,
    [radioGroupItemControlDotVars.backgroundColor]: 'currentColor',
    [radioGroupItemControlDotVars.scale]: 0.4,
  },
})

const radioGroupItemControlSizes = stylex.create({
  xs: {
    width: sizes._3,
    height: sizes._3,
  },
  sm: {
    width: sizes._3_5,
    height: sizes._3_5,
  },
  md: {
    width: sizes._4,
    height: sizes._4,
  },
  lg: {
    width: sizes._5,
    height: sizes._5,
  },
})

const radioGroupItemControlVariants = stylex.create({
  outline: {
    borderWidth: '1px',
    borderColor: {
      default: 'inherit',
      ':is([data-invalid], [aria-invalid="true"])':
        semanticColors.borderDestructive,
      ':is(:checked, [data-checked], [aria-checked="true"], [data-state="checked"])':
        colorPalette.solid,
    },
    color: {
      default: colors.white,
      ':is(:checked, [data-checked], [aria-checked="true"], [data-state="checked"])':
        colorPalette.fg,
    },
    [radioGroupItemControlDotVars.scale]: 0.6,
  },
  subtle: {
    borderWidth: '1px',
    backgroundColor: colorPalette.muted,
    borderColor: {
      default: colorPalette.muted,
      ':is([data-invalid], [aria-invalid="true"])':
        semanticColors.borderDestructive,
    },
    color: {
      default: 'transparent',
      ':is(:checked, [data-checked], [aria-checked="true"], [data-state="checked"])':
        colorPalette.fg,
    },
  },
  solid: {
    borderWidth: '1px',
    borderColor: {
      default: semanticColors.border,
      ':is([data-invalid], [aria-invalid="true"])':
        semanticColors.borderDestructive,
      ':is(:checked, [data-checked], [aria-checked="true"], [data-state="checked"])':
        colorPalette.solid,
    },
    backgroundColor: {
      default: null,
      ':is(:checked, [data-checked], [aria-checked="true"], [data-state="checked"])':
        colorPalette.solid,
    },
    color: {
      default: colors.white,
      ':is(:checked, [data-checked], [aria-checked="true"], [data-state="checked"])':
        colorPalette.contrast,
    },
  },
})

const radioGroupItemControlDot = stylex.create({
  base: {
    height: radioGroupItemControlDotVars.height,
    width: radioGroupItemControlDotVars.width,
    borderRadius: radioGroupItemControlDotVars.borderRadius,
    backgroundColor: radioGroupItemControlDotVars.backgroundColor,
    scale: radioGroupItemControlDotVars.scale,
  },
})

const radioGroupLabel = stylex.create({
  base: {
    userSelect: 'none',
    fontSize: fontSizes.sm,
    lineHeight: lineHeights.sm,
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
  },
})

export type RadioGroupVariant = keyof typeof radioGroupItemControlVariants

export type RadioGroupSize = keyof typeof radioGroupItemSizes

const radioGroupRecipe = defineSlotRecipe({
  slots: {
    item: { styles: radioGroupItem, sizes: radioGroupItemSizes },
    itemControl: {
      styles: radioGroupItemControl,
      sizes: radioGroupItemControlSizes,
      variants: radioGroupItemControlVariants,
    },
    label: { styles: radioGroupLabel },
  },
  defaultVariants: { size: "md", variant: "solid" },
});

// The indicator wraps the dot; it fills the control so the dot (a flex item
// sized 100%, as in the Ark version where it sits in the control directly)
// gets a box to fill.
const chrome = stylex.create({
  root: { display: "flex", flexDirection: "column", gap: spacing._2_5 },
  cursorPointer: { cursor: "pointer" },
  indicator: { display: "inline-flex", width: "100%", height: "100%" },
});

function ItemControlNode({
  children,
  ...props
}: React.ComponentProps<typeof UiSdkRadio>) {
  return (
    <UiSdkRadio {...props}>
      {children ?? (
        <UiSdkRadioIndicator {...stylex.props(chrome.indicator)}>
          <span {...stylex.props(radioGroupItemControlDot.base)} />
        </UiSdkRadioIndicator>
      )}
    </UiSdkRadio>
  );
}

const { withProvider, withContext } = createSlotRecipeContext(radioGroupRecipe);

const StyledRoot = withProvider(UiSdkRadioGroup, () => [chrome.root], "RadioGroupRoot");

type RawRadioGroupRootProps = React.ComponentProps<typeof StyledRoot>;
type RadioGroupOnValueChange = NonNullable<RawRadioGroupRootProps["onValueChange"]>;
type RadioGroupChangeDetails = Parameters<RadioGroupOnValueChange>[1];

function Root<T extends string = string>(
  props: Omit<RawRadioGroupRootProps, "value" | "defaultValue" | "onValueChange"> & {
    value?: T | null;
    defaultValue?: T | null;
    onValueChange?: (value: T, details: RadioGroupChangeDetails) => void;
  },
) {
  const { onValueChange, ...rest } = props;
  return (
    <StyledRoot
      {...(rest as RawRadioGroupRootProps)}
      onValueChange={
        onValueChange
          ? (next, details) => {
              if (next !== null) onValueChange(next as T, details);
            }
          : undefined
      }
    />
  );
}
Root.displayName = "RadioGroupRoot";

/**
 * Radio Group — UI SDK's radio group wearing the radio-group slot recipe.
 * `<RadioGroup.Root variant size>` resolves the recipe once and every item
 * inherits it through context. ItemControl is UI SDK's Radio (a
 * `role="radio"` button plus a hidden native radio for forms) and takes the
 * `value`; arrow keys, roving focus and form participation are UI SDK's.
 * Checked chrome targets UI SDK's `data-checked`.
 */
export const RadioGroup = {
  Root,
  Item: withContext(
    "label",
    (v) => [...resolveSlotStyles(radioGroupRecipe.slots.item, v), chrome.cursorPointer],
    "RadioGroupItem",
  ),
  ItemControl: withContext(ItemControlNode, "itemControl", "RadioGroupItemControl"),
  ItemText: withContext("span", "label", "RadioGroupItemText"),
};

export type RadioGroupRootProps = React.ComponentProps<typeof RadioGroup.Root>;
export type RadioGroupItemProps = React.ComponentProps<typeof RadioGroup.Item>;
export type RadioGroupItemControlProps = React.ComponentProps<typeof RadioGroup.ItemControl>;
export type RadioGroupItemTextProps = React.ComponentProps<typeof RadioGroup.ItemText>;
```
