Skip to content

Checkbox

A labeled checkbox with description, inline error, and an indeterminate state for select-all patterns.

Import

import { Checkbox } from "@hyzer-labs/ui"

Demo

Checkbox vs Toggle

Use Checkbox when selecting from a list, building multi-select membership, or driving the indeterminate select-all pattern. For a single on/off setting that reads like a switch, use Toggle instead.
let ace = $state(false);

<Checkbox name="ace" label="Hit an ace this round" bind:checked={ace} />

Props

NameTypeDefaultNote
namestringRequired. Form field name.
labelstringRequired. Always in the DOM; sr-only with hideLabel.
checkedbooleanfalseBindable.
indeterminatebooleanfalseSet via the DOM .indeterminate property; visual only, checked is unaffected.
valuestringSubmitted value when checked.
descriptionstringHelp text below the label.
errorstringInline error message; sets the error state.
requiredbooleanfalse
disabledbooleanfalse
hideLabelbooleanfalse
classstringMerged after the hz-field hz-field--checkbox classes.

Theme hooks

What this component promises your CSS. The reference theme styles exactly these — from @layer hz-theme, so your unlayered rules win. See Styling Components for the how.

Root class: .hz-field hz-field--checkbox

Data attributes

HookValuesStyles
data-state'default' | 'error' | 'disabled'The universal field state hook, on the root. Precedence is fixed: error beats disabled.
:checked / :indeterminatenative pseudo-classesCheckbox stamps no attribute for either — style the native pseudo-classes. (indeterminate is set as a DOM property, so only :indeterminate sees it.)

Part classes

HookValuesStyles
.hz-field-labelchild elementThe label.
.hz-field-requiredchild elementThe required marker.
.hz-field-descriptionchild elementThe hint text.
.hz-field-errorchild elementThe error message.

Accessibility

The input is associated with its label via id/for (the label renders after the box). description and error chain into aria-describedby, description first. required sets aria-required, and an error sets aria-invalid.

indeterminate is applied through the DOM .indeterminate property, so screen readers announce the mixed state natively.

References: APG Checkbox pattern · MDN: <input type="checkbox">