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.
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:
Settings and preferences
Perfect for user preference panels and configuration screens:
Multiple item selection
Great for filters, bulk actions, and multi-select lists:
Disabled and read-only states
Show options that aren't available or are system-controlled:
Controlled state management
When you need to manage checkbox state from parent components:
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.
Prop | Type | Default | Description |
---|---|---|---|
asChild | boolean | false | Change the default rendered element for the one passed as a child |
defaultChecked | boolean | "indeterminate" | - | The open state of the checkbox when initially rendered |
checked | boolean | "indeterminate" | - | The controlled checked state of the checkbox |
onCheckedChange | (checked: boolean | "indeterminate") => void | - | Event handler called when the checked state changes |
disabled | boolean | - | When true, prevents the user from interacting with the checkbox |
required | boolean | - | When true, indicates that the user must check the checkbox before submitting the form |
name | string | - | The name of the checkbox (useful when submitting an HTML form) |
value | string | on | The value given as data when submitted with a name |
Data Attributes
Attribute | Values |
---|---|
[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.
Prop | Type | Default | Description |
---|---|---|---|
asChild | boolean | false | Change the default rendered element for the one passed as a child |
forceMount | boolean | - | Used to force mounting when more control is needed |
Data Attributes
Attribute | Values |
---|---|
[data-state] | "checked" | "unchecked" | "indeterminate" |
[data-disabled] | Present when disabled |
Keyboard Navigation
Key | Description |
---|---|
Space | Checks/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
Carousel
React carousel component with touch gestures, keyboard navigation, and smooth animations. Perfect for image galleries, product showcases, and content sliders.
Collapsible
React collapsible component with smooth animations and keyboard navigation. Perfect for FAQs, navigation menus, and content sections that need to expand and collapse.