Checkbox
<cs-checkbox>
Checkboxes let users toggle an option on or off, or select multiple items from a list. They also support an indeterminate state for partial selections in groups.
This component works with standard <form> elements. See form controls for form submission and client-side validation.
Examples
Initial Value
Use the checked attribute to activate the checkbox.
checked sets the initial value, not the current state.
Consistent with native checkboxes, it doesn’t reflect later changes. To toggle the checked state with JavaScript, use the checked property instead. To target checked checkboxes with CSS, use the :state(checked) selector.
Hint
Add a descriptive hint with the hint attribute. For hints that contain HTML, use the hint slot instead.
Indeterminate
Use the indeterminate attribute to make the checkbox indeterminate. This is typically used for a “select all” control when its associated checkboxes have a mix of checked and unchecked states.
Disabled
Use the disabled attribute to disable the checkbox.
Size
Use the size attribute to change a checkbox’s size.
Custom Validity
Use the setCustomValidity() method to set a custom validation message. This will prevent the form from submitting and make the browser display the error message you provide. To clear the error, call this function with an empty string.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.
import '@cruglobal/cornerstone-components/components/checkbox/checkbox.js';
import './cornerstone/components/checkbox/checkbox.js';
import CsCheckbox from '@cruglobal/cornerstone-components/react/checkbox/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The checkbox's label. |
hint | Text that describes how to use the checkbox. Alternatively, you can use the hint attribute. |
Attributes & Properties
Learn more about attributes and properties.
| Property | Attribute | Description | Type | Default | Reflects |
|---|---|---|---|---|---|
checked | — | Draws the checkbox in a checked state. | — | — | — |
defaultChecked | checked | The default value of the form control. Primarily used for resetting the form control. | boolean | — | Yes |
disabled | disabled | Disables the checkbox. | boolean | false | — |
form | — | By default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work. | HTMLFormElement | null | — | — |
hint | hint | The checkbox's hint. If you need to display HTML, use the hint slot instead. | string | '' | — |
indeterminate | indeterminate | Draws the checkbox in an indeterminate state. This is usually applied to checkboxes that represents a "select all/none" behavior when associated checkboxes have a mix of checked and unchecked states. | boolean | false | Yes |
name | name | The name of the input, submitted as a name/value pair with form data. | string | null | null | Yes |
required | required | Makes the checkbox a required field. | boolean | false | Yes |
size | size | The checkbox's size. | 'xs' | 's' | 'm' | 'l' | 'xl' | 'm' | Yes |
ssrHint | ssr-hint | Only required for SSR. Set to true if you're slotting in a hint element. | boolean | false | — |
validationTarget | — | Override this to change where constraint validation popups are anchored. | undefined | HTMLElement | — | — |
validators | — | Validators are static because they have observedAttributes, essentially attributes to "watch" for changes. Whenever these attributes change, we want to be notified and update the validator. | Validator[] | [] | — |
value | value | The value of the checkbox, submitted as a name/value pair with form data. | string | null | — | Yes |
Methods
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
blur() | Removes focus from the checkbox. | — |
click() | Simulates a click on the checkbox. | — |
focus() | Sets focus on the checkbox. | options: FocusOptions |
formStateRestoreCallback() | Called when the browser is trying to restore element’s state to state in which case reason is "restore", or when the browser is trying to fulfill autofill on behalf of user in which case reason is "autocomplete". In the case of "restore", state is a string, File, or FormData object previously set as the second argument to setFormValue. | state: string | File | FormData | null, reason: 'autocomplete' | 'restore' |
resetValidity() | Reset validity is a way of removing manual custom errors and native validation. | — |
setCustomValidity() | Do not use this when creating a "Validator". This is intended for end users of components. We track manually defined custom errors so we don't clear them on accident in our validators. | message: string |
Events
Learn more about events.
| Name | Description |
|---|---|
blur | Emitted when the checkbox loses focus. |
change | Emitted when the checked state changes. |
cs-invalid | Emitted when the form control has been checked for validity and its constraints aren't satisfied. |
focus | Emitted when the checkbox gains focus. |
input | Emitted when the checkbox receives input. |
CSS Custom Properties
Learn more about CSS custom properties.
| Name | Description | Default |
|---|---|---|
--checked-icon-color | The color of the checked and indeterminate icons. | — |
--checked-icon-scale | The size of the checked and indeterminate icons relative to the checkbox. | — |
Custom States
Learn more about custom states.
| Name | Description | CSS selector |
|---|---|---|
checked | Applied when the checkbox is checked. | :state(checked) |
disabled | Applied when the checkbox is disabled. | :state(disabled) |
indeterminate | Applied when the checkbox is in an indeterminate state. | :state(indeterminate) |
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
checkbox | The component's outer wrapper. | ::part(checkbox) |
checked-icon | The checked icon, a <cs-icon> element. | ::part(checked-icon) |
control | The square container that wraps the checkbox's checked state. | ::part(control) |
hint | The hint's wrapper. | ::part(hint) |
icon | Whichever state icon is currently rendered, checked or indeterminate. | ::part(icon) |
indeterminate-icon | The indeterminate icon, a <cs-icon> element. | ::part(indeterminate-icon) |
label | The container that wraps the checkbox's label. | ::part(label) |
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.

