Checkbox
Give users a clear way to make selections, such as agreeing to terms or choosing multiple items from a list.
Anchor to propertiesProperties
- Anchor to accessibilityLabelaccessibilityLabelaccessibilityLabelstringstring
A label used for users using assistive technologies like screen readers. When set, any children or
labelsupplied 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.- Anchor to checkedcheckedcheckedbooleanbooleanDefault: falseDefault: false
Whether the control is active.
- Anchor to defaultCheckeddefaultCheckeddefaultCheckedbooleanbooleanDefault: falseDefault: false
Whether the control is active by default.
- Anchor to defaultIndeterminatedefaultIndeterminatedefaultIndeterminatebooleanbooleanDefault: falseDefault: false
- Anchor to detailsdetailsdetailsstringstring
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.
- Anchor to disableddisableddisabledbooleanbooleanDefault: falseDefault: false
Disables the field, disallowing any interaction.
- Anchor to errorerrorerrorstringstring
Indicate an error to the user. The field will be given a specific stylistic treatment to communicate problems that have to be resolved immediately.
- Anchor to idididstringstring
A unique identifier for the element.
- Anchor to indeterminateindeterminateindeterminatebooleanboolean
- Anchor to labellabellabelstringstring
Visual content to use as the control label.
- Anchor to namenamenamestringstring
An identifier for the field that is unique within the nearest containing form.
- Anchor to requiredrequiredrequiredbooleanbooleanDefault: falseDefault: 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
errorproperty.- Anchor to valuevaluevaluestringstring
The value used in form data when the checkbox is checked.
Anchor to eventsEvents
Learn more about registering events.
- Anchor to changechangechangeCallbackEventListener<'input'>CallbackEventListener<'input'>
- Anchor to inputinputinputCallbackEventListener<'input'>CallbackEventListener<'input'>
CallbackEventListener
(EventListener & {
(event: CallbackEvent<T>): void;
}) | nullCallbackEvent
Event & {
currentTarget: HTMLElementTagNameMap[T];
}Preview
Examples
Code
jsx
<s-checkbox label="Require a confirmation step" details="Ensure all criteria are met before proceeding" />html
<s-checkbox label="Require a confirmation step" details="Ensure all criteria are met before proceeding" ></s-checkbox>Indeterminate state
Description
Checkbox in indeterminate state, commonly used for "select all" functionality when some items are selected.
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 ( <s-stack gap="small"> <s-checkbox label="Select all items" indeterminate={selectedItems.length !== 0 && selectedItems.length !== items.length} checked={selectedItems.length === items.length} onChange={e => toggleAll(e.currentTarget.checked)} /> <s-divider /> {items.map(i => ( <s-checkbox key={i} label={i} checked={isSelected(i)} onChange={e => toggleItem(i, e.currentTarget.checked)} /> ))} </s-stack> );Error state
Description
Checkbox with validation error message for required form fields.
jsx
<s-checkbox label="I agree to the terms" error="You must accept the terms to continue" />html
<s-checkbox label="I agree to the terms" error="You must accept the terms to continue" ></s-checkbox>Help text
Description
Checkbox with descriptive details text to provide additional context about the option.
jsx
<s-checkbox label="Send order notifications" details="You'll receive emails when orders are placed, fulfilled, or cancelled" />html
<s-checkbox label="Send order notifications" details="You'll receive emails when orders are placed, fulfilled, or cancelled" ></s-checkbox>Disabled state
Description
Checkbox in disabled state with explanatory details about why it's unavailable.
jsx
<s-checkbox label="Advanced settings" disabled details="Contact your administrator to enable advanced settings" />html
<s-checkbox label="Advanced settings" disabled details="Contact your administrator to enable advanced settings" ></s-checkbox>Settings group
Description
Multiple checkboxes for different configuration options with helpful details.
jsx
<s-stack gap="base"> <s-checkbox label="Show only published products" checked /> <s-checkbox label="Enable inventory tracking" details="Track inventory levels and receive low stock alerts" checked /> <s-checkbox label="View customer data" details="Allow staff to access customer contact information and order history" /> </s-stack>html
<s-stack gap="base"> <s-checkbox label="Show only published products" checked></s-checkbox> <s-checkbox label="Enable inventory tracking" details="Track inventory levels and receive low stock alerts" checked ></s-checkbox> <s-checkbox label="View customer data" details="Allow staff to access customer contact information and order history" ></s-checkbox> </s-stack>Checkbox validation
Description
Interactive example showing required checkbox validation with dynamic error messages.
jsx
const [checked, setChecked] = useState(false); const errorMessage = 'You must accept the terms to continue'; const [error, setError] = useState(errorMessage); return ( <s-section> <s-stack gap="base" justifyContent="start"> <s-text-field label="Name" /> <s-checkbox label="I agree to the terms" checked={checked} error={error} onChange={(e) => { setChecked(e.currentTarget.checked); setError(e.currentTarget.checked ? '' : errorMessage); }} /> </s-stack> </s-section> )
Anchor to best-practicesBest practices
- Use ChoiceList when rendering multiple checkboxes to provide a consistent and accessible selection interface
- Work independently from each other
- Be framed positively (e.g., "Publish store" not "Hide store")
- Always have a label when used to activate or deactivate a setting
- Be listed in a logical order (alphabetical, numerical, time-based, etc.)
Anchor to content-guidelinesContent guidelines
- Start each option with a capital letter
- Don't use commas or semicolons at the end of each line
- Use first person when asking merchants to agree to terms (e.g., "I agree to the Terms of Service")