Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 36 ยท Inputs and Forms

Checkbox, Radio and Switch

Use Material UI selection controls: Checkbox with indeterminate state, RadioGroup, Switch, FormControlLabel and FormGroup, plus accessibility and when to pick each one.

Three controls let users make simple choices: checkboxes (zero or more options), radio buttons (exactly one of several) and switches (an immediate on/off setting). Material UI provides Checkbox, Radio and Switch, plus form helpers that attach labels and group them accessibly.

Choosing the right control

Control Use when Applies
Checkbox The user may select any number of options, or agree to something On submit
Radio Exactly one option from a short list On submit
Switch A setting that takes effect immediately (notifications, dark mode) At once

A common mistake is using a switch in a form that needs a Save button; use a checkbox there, because a switch implies instant effect.

FormControlLabel: the label wrapper

Checkbox, Radio and Switch are bare controls. To give them a clickable text label, wrap them with FormControlLabel:

JSX
import Checkbox from '@mui/material/Checkbox';
import FormControlLabel from '@mui/material/FormControlLabel';

<FormControlLabel
  control={<Checkbox checked={agree} onChange={(e) => setAgree(e.target.checked)} />}
  label="I accept the terms"
/>

The control prop receives the control element; label is the text (or any node). labelPlacement is end (default), start, top or bottom. Without FormControlLabel you must provide slotProps={{ input: { 'aria-label': '...' } }} (older: inputProps) so the control has a name.

Checkbox

A checkbox is controlled with checked and onChange; read event.target.checked, not value:

JSX
<Checkbox checked={checked} onChange={(e) => setChecked(e.target.checked)} />
<Checkbox defaultChecked />          {/* uncontrolled */}
<Checkbox disabled />
<Checkbox color="success" size="small" />
<Checkbox indeterminate />           {/* partially selected, visual only */}

A group of checkboxes lives inside FormGroup and optionally a FormControl with a FormLabel (the group's legend). The state is usually an object or an array:

JSX
<FormControl component="fieldset" variant="standard">
  <FormLabel component="legend">Toppings</FormLabel>
  <FormGroup>
    {['Cheese', 'Olives', 'Mushrooms'].map((name) => (
      <FormControlLabel
        key={name}
        control={<Checkbox checked={toppings.includes(name)} onChange={() => toggle(name)} />}
        label={name}
      />
    ))}
  </FormGroup>
  <FormHelperText>Pick as many as you like</FormHelperText>
</FormControl>

Rendering the group as a fieldset with a legend tells screen readers what the group is about.

The indeterminate "select all"

indeterminate shows a dash when some, but not all, children are checked. It is only visual: you decide when to set it, usually for a "select all" parent. The next stand-in builds this classic pattern.

Stand-in: Checkbox group with an indeterminate parent

Radio and RadioGroup

Radio buttons only make sense in a group. RadioGroup holds the single selected value, each Radio has its own value, and FormControl plus FormLabel name the group:

JSX
import RadioGroup from '@mui/material/RadioGroup';
import Radio from '@mui/material/Radio';
import FormLabel from '@mui/material/FormLabel';

<FormControl>
  <FormLabel id="plan-label">Plan</FormLabel>
  <RadioGroup
    aria-labelledby="plan-label"
    name="plan"
    value={plan}
    onChange={(e) => setPlan(e.target.value)}
  >
    <FormControlLabel value="free" control={<Radio />} label="Free" />
    <FormControlLabel value="pro" control={<Radio />} label="Pro" />
    <FormControlLabel value="team" control={<Radio />} label="Team" disabled />
  </RadioGroup>
</FormControl>
  • The selected value is a string (even if your ids are numbers; convert in your handler).
  • Put row on RadioGroup for a horizontal list.
  • Keyboard: arrow keys move between radios and select them; Tab leaves the group. This works because the radios share the name.
  • Always provide a default selection when one choice is required; radios cannot be unselected by the user.

Switch

Switch looks like a toggle and is used for settings with immediate effect. It is controlled with checked/onChange, like Checkbox:

JSX
<FormControlLabel
  control={<Switch checked={notifications} onChange={(e) => setNotifications(e.target.checked)} />}
  label="Email notifications"
/>
<Switch size="small" color="success" />

Use a clear label that describes the on state ("Dark mode", not "Toggle"), and avoid using colors alone to show state. Saving to a server should happen in onChange, with the switch disabled or optimistic while the request runs.

Stand-in: radio group and switches

The second stand-in builds a settings panel: a radio group for the plan and switches that apply immediately, reflected in a summary line.

Stand-in: RadioGroup and Switch settings panel

Accessibility notes

  • Every control needs a visible label (FormControlLabel) or an aria-label.
  • Group related controls in a fieldset with a legend (FormControl component="fieldset" + FormLabel component="legend"), or RadioGroup with aria-labelledby.
  • Do not rely on color alone to show checked state; MUI draws a check mark, a dot or a thumb position.
  • Hit areas of the default controls are 42px, so they work on touch screens; keep them that way when customizing.

Common mistakes

  • Reading event.target.value of a checkbox instead of event.target.checked.
  • Mixing checked and defaultChecked (controlled and uncontrolled).
  • Radio values that are numbers: the event gives a string.
  • Placing a Switch where users expect a Save button to confirm.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which event property holds the state of a Checkbox?

    A checkbox reports its boolean state through checked.
  2. 2. What is FormControlLabel for?

    It wraps a control passed in the control prop and renders the label so clicking the text toggles the control.
  3. 3. The indeterminate prop of Checkbox...

    indeterminate is visual; you compute it, typically for a select-all parent.
  4. 4. When is a Switch more appropriate than a Checkbox?

    Switches imply immediate effect; checkboxes are for choices applied on submit.

Summary

  • Checkbox: zero or more choices; Radio: exactly one; Switch: instant on/off setting.
  • Wrap controls in FormControlLabel and group them with FormGroup/RadioGroup inside a FormControl with a legend.
  • Read checked for checkboxes and switches; RadioGroup holds one string value.
  • indeterminate is visual only; compute it yourself for "select all".
  • Always provide accessible names and group labels.

Next: Slider, Rating and Toggle Buttons