Join our Discord Community

Checkbox

React checkbox component with three states, keyboard navigation, and form integration. Perfect for terms acceptance, settings toggles, and multi-select lists.

Need users to agree to terms? Building a settings panel with toggles? The Checkbox component handles everything from simple yes/no choices to complex multi-selection with indeterminate states.

Loading component...

Built with accessibility in mind and works perfectly in forms, data tables, and anywhere you need user selection.

npx shadcn@latest add checkbox

Why checkboxes work everywhere

Users know exactly what to expect from checkboxes:

  • Three clear states - Unchecked, checked, and indeterminate for partial selections
  • Keyboard accessible - Space bar toggles, Tab navigation works perfectly
  • Form friendly - Integrates seamlessly with React Hook Form and native forms
  • Screen reader support - ARIA attributes built in for accessibility
  • Visual feedback - Smooth animations and focus states feel professional
  • Touch optimized - Works great on mobile devices

Common checkbox patterns you'll need

Accept terms and conditions

The classic signup flow checkbox that everyone recognizes:

Loading component...

Settings and preferences

Perfect for user preference panels and configuration screens:

Loading component...

Multiple item selection

Great for filters, bulk actions, and multi-select lists:

Loading component...

Disabled and read-only states

Show options that aren't available or are system-controlled:

Loading component...

Controlled state management

When you need to manage checkbox state from parent components:

Loading component...

API Reference

Checkbox

Contains all the parts of a checkbox. An input will also render when used within a form to ensure events propagate correctly.

PropTypeDefaultDescription
asChildbooleanfalseChange the default rendered element for the one passed as a child
defaultCheckedboolean | "indeterminate"-The open state of the checkbox when initially rendered
checkedboolean | "indeterminate"-The controlled checked state of the checkbox
onCheckedChange(checked: boolean | "indeterminate") => void-Event handler called when the checked state changes
disabledboolean-When true, prevents the user from interacting with the checkbox
requiredboolean-When true, indicates that the user must check the checkbox before submitting the form
namestring-The name of the checkbox (useful when submitting an HTML form)
valuestringonThe value given as data when submitted with a name

Data Attributes

AttributeValues
[data-state]"checked" | "unchecked" | "indeterminate"
[data-disabled]Present when disabled

CheckboxIndicator

Renders when the checkbox is in a checked or indeterminate state. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.

PropTypeDefaultDescription
asChildbooleanfalseChange the default rendered element for the one passed as a child
forceMountboolean-Used to force mounting when more control is needed

Data Attributes

AttributeValues
[data-state]"checked" | "unchecked" | "indeterminate"
[data-disabled]Present when disabled

Keyboard Navigation

KeyDescription
SpaceChecks/unchecks the checkbox

Checkbox best practices

What makes checkboxes feel natural and accessible:

  • Clear labels - "I agree to the Terms of Service" beats "I agree"
  • Logical grouping - Related checkboxes should be visually grouped together
  • Smart defaults - Pre-check options that most users want (like "Remember me")
  • Indeterminate for groups - Show partial selection in parent checkboxes
  • Accessible spacing - Enough space between checkboxes for touch targets
  • Immediate feedback - Visual changes happen instantly when clicked
  • Form validation - Clear error messages when required checkboxes aren't checked
  • Keyboard support - Space bar and Tab navigation work perfectly