Checkbox

Material Design 3 checkbox component with multiple variants, sizes, and states

Checkbox

Native Contract And Imports

Individual example prerequisites (including composition and demo actions):

@import "@duskmoon-dev/core/base.css";
@import "@duskmoon-dev/core/themes/sunshine";
@import "@duskmoon-dev/core/components/checkbox.css";
@import "@duskmoon-dev/core/components/form-group.css";
@import "@duskmoon-dev/core/components/button.css";

base.css supplies global focus/utility definitions and shared spacing/shape tokens; use your framework reset when appropriate. Substitute the Moonlight theme for dark forms.

Aggregate: @duskmoon-dev/core with Tailwind v4; no-Tailwind: @duskmoon-dev/core/standalone.css. Individual: @duskmoon-dev/core/components/checkbox.css plus base/theme and form-group.css for associated labels/help. Extensionless components/checkbox exports generated css and constructable styles, not a behavior runtime.

Use native inputs for values, selection, constraints, submission and reset. Actual disabled or fieldset disabled owns semantic disabling. Use .validator for native interaction-based errors and add .validator-success for native success. Explicit aria-invalid="true" wins over those states and color modifiers, including focus. Supply described error text as well as color. See Validator and Field composition.

Checked state and reset are native. Indeterminate is an application-set DOM property, not an HTML attribute or a submitted third value. Resynchronize it after reset if needed.

Checkboxes allow users to select one or more items from a set or toggle a single option. @duskmoon-dev/core provides a complete set of Material Design 3 checkbox variants with support for checked, indeterminate, and disabled states.

Basic Usage

Simply add the .checkbox class to an <input type="checkbox">:

Basic Checkbox

With Label

Wrap the checkbox in a label for better UX:

Checkbox with Label

Checked State

Checked Checkbox

Sizes

Five sizes are available:

Checkbox Sizes

Color Variants

Primary (Default)

Primary Checkbox

Secondary

Secondary Checkbox

Tertiary

Tertiary Checkbox

Success

Success Checkbox

Warning

Warning Checkbox

Error

Error Checkbox

Info

Info Checkbox

All Colors Comparison

All Color Variants

States

Indeterminate

The indeterminate (mixed) state represents a partially selected state, commonly used in “select all” scenarios. Set it via JavaScript:

Indeterminate Checkbox

Indeterminate Color Variants

All color variants support the indeterminate state:

Indeterminate Colors

Select All Pattern

A common use case for the indeterminate state is “select all” checkboxes:

Select All Example

The local demo script owns aggregate checked/indeterminate state and reset synchronization. Only the named item controls are submitted; the select-all control is not another value.

Disabled

Disabled Checkboxes

Checkbox Groups

Vertical Group

Vertical Checkbox Group

Select your interests

Horizontal Group

Horizontal Checkbox Group

Form Integration

Checkbox in Form

Notification Preferences

Best Practices

Accessibility

  • Use semantic <label> elements to associate labels with checkboxes
  • Provide clear, descriptive labels
  • Use fieldset and legend for checkbox groups
  • Ensure sufficient color contrast

Touch Targets

The checkbox provides adequate touch targets. For mobile-first designs, use larger sizes:

Mobile-Friendly Checkbox

API Reference

Class Names

Class Description
.checkbox Base checkbox styling (required, on input element)
.checkbox-xs Extra small size (14px)
.checkbox-sm Small size (16px)
.checkbox-md Medium size (20px, default)
.checkbox-lg Large size (24px)
.checkbox-xl Extra large size (28px)
.checkbox-primary Primary color variant (default)
.checkbox-secondary Secondary color variant
.checkbox-tertiary Tertiary color variant
.checkbox-success Success color variant
.checkbox-warning Warning color variant
.checkbox-error Error color variant
.checkbox-info Info color variant
.checkbox-label Label wrapper for checkbox + text
.checkbox-group Container for vertical checkbox group
.checkbox-group-horizontal Horizontal layout modifier
.checkbox-group-label Group label text

HTML Structure

Simple checkbox:

<input type="checkbox" class="checkbox" aria-label="Example checkbox" />

With label:

<label class="checkbox-label">
  <input type="checkbox" class="checkbox" />
  <span>Label text</span>
</label>

States

State How to Apply
Checked checked attribute
Disabled disabled attribute
Indeterminate element.indeterminate = true (JavaScript)
Focus Automatic via :focus-visible

Ghost Variant

The ghost variant removes the visible border when unchecked — useful for minimal UI contexts.

Ghost Checkbox

  • Radio - Single selection input
  • Switch - Toggle control
  • Input - Text input fields