Checkbox
A checkbox toggles a single option, or a set of them, independently of one another. It supports checked, unchecked, and indeterminate states, and submits a real <input> with the form.
The component is composed from parts. <Checkbox> owns the state machine; the remaining parts read it from context, so they must all be rendered inside <Checkbox>.
Interactive Preview
Section titled “Interactive Preview”import { Checkbox, CheckboxControl, CheckboxIndicator, CheckboxLabel,} from "@/components/ui/checkbox";
export function TermsAgreement() { return ( <Checkbox name="terms" value="accepted" defaultChecked> <CheckboxControl> <CheckboxIndicator /> </CheckboxControl> <CheckboxLabel>I agree to the terms of service</CheckboxLabel> </Checkbox> );}<script lang="ts"> import Checkbox from "@/components/ui/checkbox.svelte"; import CheckboxControl from "@/components/ui/checkbox-control.svelte"; import CheckboxIndicator from "@/components/ui/checkbox-indicator.svelte"; import CheckboxLabel from "@/components/ui/checkbox-label.svelte";</script>
<Checkbox name="terms" value="accepted" defaultChecked> <CheckboxControl> <CheckboxIndicator /> </CheckboxControl> <CheckboxLabel>I agree to the terms of service</CheckboxLabel></Checkbox>import { Checkbox, CheckboxControl, CheckboxIndicator, CheckboxLabel,} from "@/components/ui/checkbox";
export function TermsAgreement() { return ( <Checkbox name="terms" value="accepted" defaultChecked> <CheckboxControl> <CheckboxIndicator /> </CheckboxControl> <CheckboxLabel>I agree to the terms of service</CheckboxLabel> </Checkbox> );}Installation
Section titled “Installation”npx @glaceon/cli add checkbox --framework react # or svelte, solidData Attributes
Section titled “Data Attributes”| Attribute | Values | Applied to |
|---|---|---|
data-scope |
checkbox |
every part |
data-part |
root, control, indicator, label, hidden-input |
matching part |
data-state |
checked, unchecked, indeterminate |
root, control, label |
Two behaviours are essential when styling this component:
- The indicator carries the
hiddenattribute unless the box is checked or indeterminate. Give it no unconditional display utility: aflexwould tie with[hidden]on specificity and win, leaving the checkmark visible when unchecked. - The radio dot in Radio Group depends on
groupbeing present on the control. The same rule applies to anygroup-data-[...]styling you add.
API Reference (Props)
Section titled “API Reference (Props)”| Part | Prop | Type | Description |
|---|---|---|---|
Checkbox |
children |
content | The root row |
Checkbox |
defaultChecked |
boolean | "indeterminate" |
Initial state |
Checkbox |
checked |
boolean | "indeterminate" |
Controlled state |
Checkbox |
disabled |
boolean |
Prevents interaction |
Checkbox |
name / value |
string |
Submitted with the form |
Checkbox |
onCheckedChange |
(details) => void |
Called when the state changes |
CheckboxRoot |
children |
content | Control and label |
CheckboxIndicator |
className / class |
string |
The check or dash glyph |
Every part also accepts className (React) or class (Svelte, Solid), merged with cn().
Keyboard Interactions
Section titled “Keyboard Interactions”| Key | Behaviour |
|---|---|
Space |
Toggles the checkbox when it is focused |
Tab |
Moves focus to and from the checkbox |
Accessibility
Section titled “Accessibility”Zag.js renders a real <input> in the root, so the checkbox participates in form submission and is announced correctly. The root is a <label> wrapping the control, which gives the whole row a 44px touch target (WCAG 2.2 SC 2.5.8) while the visible box stays 20px. Focus rings use the --action token at 2px.