Skip to content

Radio Group

The Radio Group allows the user to select one option from a set.

Use radio buttons when the user needs to see all available options. If available options can be collapsed, consider using a Select component because it uses less space.

Radio buttons should have the most commonly used option selected by default.

Radio group

RadioGroup is a helpful wrapper used to group Radio components that provides an easier API, and proper keyboard accessibility to the group.

Press Enter to start editing

Direction

To lay out the buttons horizontally, set the row prop:

Controlled

You can control the radio with the value and onChange props:

Press Enter to start editing

Standalone radio buttons

Radio can also be used standalone, without the RadioGroup wrapper.

Press Enter to start editing

Size

Use the size prop or customize the font size of the svg icons to change the size of the radios.

Press Enter to start editing

Color

Press Enter to start editing

Label placement

You can change the placement of the label with the FormControlLabel component's labelPlacement prop:

Show error

In general, radio buttons should have a value selected by default. If this is not the case, you can display an error if no value is selected when the form is submitted:

Choose wisely

Customization

Here is an example of customizing the component. You can learn more about this in the overrides documentation page.

useRadioGroup

For advanced customization use cases, a useRadioGroup() hook is exposed. It returns the context value of the parent radio group. The Radio component uses this hook internally.

API

<span class="token keyword">import</span> <span class="token punctuation">{</span> useRadioGroup <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@mui/material/RadioGroup'</span><span class="token punctuation">;</span>

Returns

value (object):

  • value.name (string [optional]): The name used to reference the value of the control.
  • value.onChange (func [optional]): Callback fired when a radio button is selected.
  • value.value (any [optional]): Value of the selected radio button.

Example

Press Enter to start editing

When to use

Accessibility

(WAI-ARIA: https://www.w3.org/WAI/ARIA/apg/patterns/radio/)

  • All form controls should have labels, and this includes radio buttons, checkboxes, and switches. In most cases, this is done by using the <label> element (FormControlLabel).

  • When a label can't be used, it's necessary to add an attribute directly to the input component. In this case, you can apply the additional attribute (e.g. aria-label, aria-labelledby, title) via the inputProps property.

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Radio</span></span>
  <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>radioA<span class="token punctuation">"</span></span>
  <span class="token attr-name">inputProps</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>
    <span class="token string-property property">'aria-label'</span><span class="token operator">:</span> <span class="token string">'Radio A'</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">}</span></span>
<span class="token punctuation">/></span></span>

API

See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.