Checkbox
Animated custom checkbox with label, hint, disabled, and indeterminate states.
Import
import Checkbox from '$lib/components/Checkbox.svelte';Usage
<Checkbox bind:checked={value} label="Remember me" />Basic
With label and optional hint text.
<Checkbox bind:checked={value} label="Remember me" />
<Checkbox bind:checked={value} label="Enable notifications" hint="New follower and like notifications" />States
Disabled and indeterminate states.
<Checkbox checked={false} label="Disabled (unchecked)" disabled />
<Checkbox checked={true} label="Disabled (checked)" disabled />
<Checkbox indeterminate label="Indeterminate" hint="Some items selected" />Select All
Select all with indeterminate state for partial selections.
<Checkbox
checked={allChecked}
indeterminate={someChecked}
label="Select all"
onchange={toggleAll}
/>
<div class="ml-8">
{#each fruits as fruit}
<Checkbox bind:checked={fruit.checked} label={fruit.label} />
{/each}
</div>Use Case — Sign Up Form
Real-world form example with required field validation.
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | false | Bindable checked state of the checkbox. |
label | string | — | Text label displayed next to the checkbox. |
hint | string | — | Secondary hint text shown below the label. |
disabled | boolean | false | Prevents interaction and reduces opacity. |
indeterminate | boolean | false | Shows a dash to indicate a partially selected state. |
onchange | (v: boolean) => void | — | Callback fired when the checked state changes. |