--- title: Checkbox description: >- Give users a clear way to make selections, such as agreeing to terms or choosing multiple items from a list. api_name: app-home source_url: html: 'https://shopify.dev/docs/api/app-home/polaris-web-components/forms/checkbox' md: >- https://shopify.dev/docs/api/app-home/polaris-web-components/forms/checkbox.md --- # Checkbox Give users a clear way to make selections, such as agreeing to terms or choosing multiple items from a list. ## Properties * accessibilityLabel string A label used for users using assistive technologies like screen readers. When set, any children or `label` supplied will not be announced. This can also be used to display a control without a visual label, while still providing context to users using screen readers. * checked boolean Default: false Whether the control is active. * defaultChecked boolean Default: false Whether the control is active by default. * defaultIndeterminate boolean Default: false * details string Additional text to provide context or guidance for the field. This text is displayed along with the field and its label to offer more information or instructions to the user. This will also be exposed to screen reader users. * disabled boolean Default: false Disables the field, disallowing any interaction. * error string Indicate an error to the user. The field will be given a specific stylistic treatment to communicate problems that have to be resolved immediately. * id string A unique identifier for the element. * indeterminate boolean * label string Visual content to use as the control label. * name string An identifier for the field that is unique within the nearest containing form. * required boolean Default: false Whether the field needs a value. This requirement adds semantic value to the field, but it will not cause an error to appear automatically. If you want to present an error when this field is empty, you can do so with the `error` property. * value string The value used in form data when the checkbox is checked. ## Events Learn more about [registering events](https://shopify.dev/docs/api/app-home/using-polaris-components#event-handling). * change CallbackEventListener<'input'> * input CallbackEventListener<'input'> ### CallbackEventListener ```ts (EventListener & { (event: CallbackEvent): void; }) | null ``` ### CallbackEvent ```ts Event & { currentTarget: HTMLElementTagNameMap[T]; } ``` ### Examples * #### Code ##### jsx ```jsx ``` ##### html ```html ``` ## Examples Component examples ### Basic usage Indeterminate state Checkbox in indeterminate state, commonly used for "select all" functionality when some items are selected. Error state Checkbox with validation error message for required form fields. Help text Checkbox with descriptive details text to provide additional context about the option. Disabled state Checkbox in disabled state with explanatory details about why it's unavailable. Settings group Multiple checkboxes for different configuration options with helpful details. ### Examples * #### Indeterminate state ##### Description Checkbox in indeterminate state, commonly used for "select all" functionality when some items are selected. ##### jsx ```jsx const [selectedItems, setSelectedItems] = useState([]); const items = ['Item 1', 'Item 2', 'Item 3']; const toggleItem = (value, checked) => setSelectedItems(checked ? [...selectedItems, value] : selectedItems.filter(item => item !== value)); const toggleAll = (checked) => setSelectedItems(checked ? items : []); const isSelected = (item) => selectedItems.includes(item); return ( toggleAll(e.currentTarget.checked)} /> {items.map(i => ( toggleItem(i, e.currentTarget.checked)} /> ))} ); ``` * #### Error state ##### Description Checkbox with validation error message for required form fields. ##### jsx ```jsx ``` ##### html ```html ``` * #### Help text ##### Description Checkbox with descriptive details text to provide additional context about the option. ##### jsx ```jsx ``` ##### html ```html ``` * #### Disabled state ##### Description Checkbox in disabled state with explanatory details about why it's unavailable. ##### jsx ```jsx ``` ##### html ```html ``` * #### Settings group ##### Description Multiple checkboxes for different configuration options with helpful details. ##### jsx ```jsx ``` ##### html ```html ``` ### Form validation Checkbox validation Interactive example showing required checkbox validation with dynamic error messages. ### Examples * #### Checkbox validation ##### Description Interactive example showing required checkbox validation with dynamic error messages. ##### jsx ```jsx const [checked, setChecked] = useState(false); const errorMessage = 'You must accept the terms to continue'; const [error, setError] = useState(errorMessage); return ( { setChecked(e.currentTarget.checked); setError(e.currentTarget.checked ? '' : errorMessage); }} /> ) ```