Course contentsShow
← React
Lesson 502 of 2,39614. Uncontrolled ComponentsFree lesson

defaultChecked for Checkboxes and Radio Buttons

Initialize checkboxes and radio buttons as checked or unchecked while letting the DOM manage their state.

defaultChecked for Checkboxes and Radio Buttons

You'll learn how to set the initial checked state of checkboxes and radio buttons in uncontrolled components.

The Core Idea

Just like text inputs use defaultValue to set an initial value without controlling it, checkboxes and radio buttons use defaultChecked to set their initial checked/unchecked state. After that initial setup, the DOM takes over and manages whether they're checked or not.

Think of it like pre-setting a light switch before you leave for the day. You flip it to "on" initially (defaultChecked={true}), but after that, anyone can flip it up or down without you tracking every change. You only care about the initial position.

The Syntax

// Checkbox starts checked
<input 
  type="checkbox" 
  ref={checkboxRef}
  defaultChecked={true}
/>

// Radio button starts selected
<input 
  type="radio" 
  name="choice"
  value="option-a"
  ref={radioRef}
  defaultChecked={true}
/>

// Checkbox starts unchecked (could omit defaultChecked entirely)
<input 
  type="checkbox" 
  ref={anotherRef}
  defaultChecked={false}
/>

When to Use It

Use defaultChecked when you want to initialize a checkbox or radio button's state but don't need to track every change in React state. You'll typically read the final value using a ref when the form is submitted, just like with defaultValue inputs.

This is perfect for simple forms where you only care about the values at submission time, not during every interaction.

Remember the Distinction

  • checked prop → controlled (requires onChange, React manages state)
  • defaultChecked prop → uncontrolled (no onChange needed, DOM manages state)

Key Takeaway: Use defaultChecked to set the initial checked state of checkboxes and radio buttons in uncontrolled components—the DOM handles all subsequent changes without React state updates.