Checkbox

A form control that allows users to select one or more options from a set.

Anatomy

<script>
  import {
    Checkbox,
    CheckboxControl,
    CheckboxLabel,
    CheckboxIndicator,
    CheckboxGroup,
  } from "@saas-ui/svelte/components/checkbox";
</script>

<!-- Simple checkbox with label -->
<Checkbox.Root label="Accept terms" />

<!-- Checkbox group -->
<CheckboxGroup label="Select options">
  <Checkbox.Root label="Option 1" value="1" />
  <Checkbox.Root label="Option 2" value="2" />
  <Checkbox.Root label="Option 3" value="3" />
</CheckboxGroup>

Examples

Basic Accessibility

Basic checkbox with label and default styling.

Colours Accessibility

Use the colour prop to change the colour scheme. Supports all standard colour palettes.

Controlled Accessibility

Controlled checkbox with bound checked state for programmatic control.

Custom Icon Accessibility

Checkbox with a custom icon instead of the default checkmark.

Description Accessibility

Checkbox with additional description text for extra context.

Group Accessibility

Use Checkbox.Group to group related checkboxes with shared state management.

Indeterminate Accessibility

Indeterminate state for parent checkbox when only some child checkboxes are selected.

Sizes Accessibility

Use the size prop to change the size of the checkbox. Available sizes: sm, md, lg.

States Accessibility

Checkbox states including disabled and invalid for form validation.

Variants Accessibility

Use the variant prop to change the visual style. Available variants: outline, subtle, solid.

Props

Checkbox.Root

The root checkbox component.

Prop Type Default Description
children Snippet - Content to render inside the checkbox (composition API).
label string - The label text displayed next to the checkbox.
class string - Additional CSS classes to apply.
size "sm" | "md" | "lg" "md" The size of the checkbox.
variant "solid" | "subtle" | "outline" "solid" The visual style of the checkbox.
colour ColourName "indigo" The colour palette of the checkbox.
checked boolean | "indeterminate" false The controlled checked state of the checkbox.
defaultChecked boolean - The default checked state when uncontrolled.
value string - The value of the checkbox (used in groups).
name string - The name of the input field.
disabled boolean false Whether the checkbox is disabled.
invalid boolean false Whether the checkbox is in an invalid state.
required boolean false Whether the checkbox is required.
icon Component<any> - Custom icon component to render when checked. Auto-sized to fill the checkbox.
onCheckedChange (details: { checked: boolean | "indeterminate" }) => void - Callback invoked when the checked state changes.

Checkbox.Control

The visual control element for the checkbox (the box itself).

Prop Type Default Description
children Snippet - The content of the control (usually indicators).
class string - Additional classes to apply to the control.
checked boolean | "indeterminate" false Whether the checkbox is checked.

Checkbox.Indicator

The indicator element that shows when the checkbox is checked.

Prop Type Default Description
children Snippet - The content of the indicator (usually an icon).
indeterminate boolean false Whether this indicator is for the indeterminate state.
class string - Additional classes to apply to the indicator.

Checkbox.Label

The text label for the checkbox.

Prop Type Default Description
children Snippet - The content of the label.
class string - Additional classes to apply to the label.

Checkbox.Group

A container for grouping related checkboxes with shared state.

Prop Type Default Description
children Snippet - Content to render inside the group.
orientation "horizontal" | "vertical" "vertical" The layout orientation of the group.
label string - The label displayed above the group.
value string[] - The controlled value of the checkbox group.
defaultValue string[] - The default value of the checkbox group when uncontrolled.
name string - The name of the input fields in the checkbox group (useful for form submission).
disabled boolean - Whether the checkbox group is disabled.
readOnly boolean - Whether the checkbox group is read-only.
invalid boolean - Whether the checkbox group is invalid.
onValueChange (value: string[]) => void - Callback invoked when the value changes.
class string - Additional CSS classes to apply.

Checkbox.HiddenInput

A hidden input element for form submission and accessibility.

Prop Type Default Description