Skip to contents

Radio

An easily stylable radio button component.

View as Markdown
Best apple

Usage guidelines

  • Form controls must have an accessible name: It can be created using <label> elements, the Label component, or the Field and Fieldset components. See Labeling a radio group and the forms guide.

Anatomy

Radio is always placed within Radio Group. Import the components and place them together:

Anatomy

Examples

Labeling a radio group

A visible label for the group is created by specifying aria-labelledby on <RadioGroup> to reference the id of a sibling element that contains the group label text.

Using aria-labelledby to label a radio group

For individual radio buttons, use the Label component. It supports the same enclosing labeling pattern as a native <label>, so clicking on any gaps between the label text and radio still toggles it.

Using Label to label a radio button

The Field and Fieldset components are alternatives that add validation and group labeling support.

  1. Group label: Since the group contains multiple controls, it can be labeled as a fieldset. Use Fieldset by replacing the <Fieldset.Root> element with <RadioGroup> via the render prop. <Fieldset.Legend> provides the visible label for the group.
  2. Individual label: Place each individual radio in <Field.Item>, then label it using an enclosing <Field.Label>. Enclosing labels ensure that clicking on any gaps between the label and radio still toggles it.
Using Field and Fieldset to label a radio group

Form integration

To use a radio group in a form, pass the radio group’s name to <Field.Root>:

Using Radio Group in a form

API reference

RadioGroup

Provides a shared state to a series of radio buttons. Renders a <div> element.

namestring
Name
Description

Identifies the field when a form is submitted.

Type
string | undefined
defaultValueValue
Description

The uncontrolled value of the radio button that should be initially selected.

To render a controlled radio group, use the value prop instead.

Type
Value | undefined
valueValue
Name
Description

The controlled value of the radio item that should be currently selected.

To render an uncontrolled radio group, use the defaultValue prop instead.

Type
Value | undefined
onValueChangefunction
Description

Callback fired when the value changes.

Type
| ((
    value: Value,
    eventDetails: Radio.Group.ChangeEventDetails,
  ) => void)
| undefined
disabledbooleanfalse
Description

Whether the component should ignore user interaction.

Type
boolean | undefined
Default
false
readOnlybooleanfalse
Description

Whether the user should be unable to select a different radio button in the group.

Type
boolean | undefined
Default
false
requiredbooleanfalse
Description

Whether the user must choose a value before submitting a form.

Type
boolean | undefined
Default
false
inputRefRef<HTMLInputElement>
Description

A ref to access the hidden input element.

Type
React.Ref<HTMLInputElement> | undefined
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
| string
| ((state: RadioGroup.State) => string | undefined)
styleReact.CSSProperties | function
Name
Type
| React.CSSProperties
| ((state: RadioGroup.State) => CSSProperties | undefined)
| undefined
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
| ReactElement
| ((
    props: HTMLProps,
    state: RadioGroup.State,
  ) => ReactElement)
data-disabled
Present when the radio group is disabled.

Root

Represents the radio button itself. Renders a <span> element and a hidden <input> beside.

value*Value
Name
Description

The unique identifying value of the radio in a group.

Type
Value
nativeButtonbooleanfalse
Description

Whether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.

Type
boolean | undefined
Default
false
disabledboolean
Description

Whether the component should ignore user interaction.

Type
boolean | undefined
readOnlyboolean
Description

Whether the user should be unable to select the radio button.

Type
boolean | undefined
requiredboolean
Description

Whether the user must choose a value before submitting a form.

Type
boolean | undefined
inputRefRef<HTMLInputElement>
Description

A ref to access the hidden input element.

Type
React.Ref<HTMLInputElement> | undefined
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
| string
| ((state: Radio.Root.State) => string | undefined)
styleReact.CSSProperties | function
Name
Type
| React.CSSProperties
| ((state: Radio.Root.State) => CSSProperties | undefined)
| undefined
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
| ReactElement
| ((
    props: HTMLProps,
    state: Radio.Root.State,
  ) => ReactElement)
data-checked
Present when the radio is checked.
data-unchecked
Present when the radio is not checked.
data-disabled
Present when the radio is disabled.
data-readonly
Present when the radio is readonly.
data-required
Present when the radio is required.
data-valid
Present when the radio is in valid state (when wrapped in Field.Root).
data-invalid
Present when the radio is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the radio's value has changed (when wrapped in Field.Root).
data-touched
Present when the radio has been touched (when wrapped in Field.Root).
data-filled
Present when the radio is checked (when wrapped in Field.Root).
data-focused
Present when the radio is focused (when wrapped in Field.Root).

Indicator

Indicates whether the radio button is selected. Renders a <span> element.

classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
| string
| ((state: Radio.Indicator.State) => string | undefined)
styleReact.CSSProperties | function
Name
Type
| React.CSSProperties
| ((
    state: Radio.Indicator.State,
  ) => CSSProperties | undefined)
| undefined
keepMountedbooleanfalse
Description

Whether to keep the HTML element in the DOM when the radio button is inactive.

Type
boolean | undefined
Default
false
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
| ReactElement
| ((
    props: HTMLProps,
    state: Radio.Indicator.State,
  ) => ReactElement)
data-checked
Present when the radio is checked.
data-unchecked
Present when the radio is not checked.
data-disabled
Present when the radio is disabled.
data-readonly
Present when the radio is readonly.
data-required
Present when the radio is required.
data-valid
Present when the radio is in valid state (when wrapped in Field.Root).
data-invalid
Present when the radio is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the radio's value has changed (when wrapped in Field.Root).
data-touched
Present when the radio has been touched (when wrapped in Field.Root).
data-filled
Present when the radio is checked (when wrapped in Field.Root).
data-focused
Present when the radio is focused (when wrapped in Field.Root).
data-starting-style
Present when the radio indicator is animating in.
data-ending-style
Present when the radio indicator is animating out.