Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

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>.

React Checkboxlive
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>
);
}
Terminal window
npx @glaceon/cli add checkbox --framework react # or svelte, solid
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 hidden attribute unless the box is checked or indeterminate. Give it no unconditional display utility: a flex would tie with [hidden] on specificity and win, leaving the checkmark visible when unchecked.
  • The radio dot in Radio Group depends on group being present on the control. The same rule applies to any group-data-[...] styling you add.
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().

Key Behaviour
Space Toggles the checkbox when it is focused
Tab Moves focus to and from the checkbox

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.