Checkbox
A binary input control for selecting true or false states
Basic Usage
Get notified about updates and new features
1
2<script lang="ts">
3 import { Checkbox } from "@kareyes/aether";
4
5 let basicChecked = $state(false);
6 let withLabelChecked = $state(false);
7 let withDescriptionChecked = $state(false);
8</script>
9
10<div class="space-y-4">
11 <Checkbox bind:checked={basicChecked} />
12 <Checkbox
13 bind:checked={withLabelChecked}
14 label="Accept terms and conditions"
15 />
16 <Checkbox
17 bind:checked={withDescriptionChecked}
18 label="Enable notifications"
19 description="Get notified about updates and new features"
20 />
21</div>Sizes
1
2<script lang="ts">
3 import { Checkbox } from "@kareyes/aether";
4
5 let smallChecked = $state(false);
6 let defaultChecked = $state(false);
7 let largeChecked = $state(false);
8 let xlChecked = $state(false);
9</script>
10
11<div class="flex items-center gap-6">
12 <Checkbox bind:checked={smallChecked} size="sm" label="Small" />
13 <Checkbox bind:checked={defaultChecked} size="default" label="Default" />
14 <Checkbox bind:checked={largeChecked} size="lg" label="Large" />
15 <Checkbox bind:checked={xlChecked} size="xl" label="Extra Large" />
16</div>Variants
This action cannot be undone
This will mark the task as done
This action requires attention
1
2<script lang="ts">
3 import { Checkbox } from "@kareyes/aether";
4
5 let destructiveChecked = $state(false);
6 let successChecked = $state(false);
7 let warningChecked = $state(false);
8</script>
9
10<div class="space-y-4">
11 <Checkbox
12 bind:checked={destructiveChecked}
13 variant="destructive"
14 label="Delete all data"
15 description="This action cannot be undone"
16 />
17 <Checkbox
18 bind:checked={successChecked}
19 variant="success"
20 label="Mark as completed"
21 description="This will mark the task as done"
22 />
23 <Checkbox
24 bind:checked={warningChecked}
25 variant="warning"
26 label="Proceed with caution"
27 description="This action requires attention"
28 />
29</div>Line Through Feature
This text gets crossed out when checked
1
2<script lang="ts">
3 import { Checkbox } from "@kareyes/aether";
4
5 let lineThroughChecked = $state(true);
6</script>
7
8<Checkbox
9 bind:checked={lineThroughChecked}
10 lineThrough={true}
11 label="Completed task with line-through"
12 description="This text gets crossed out when checked"
13/>Indeterminate State
This checkbox is in an indeterminate state
1
2<script lang="ts">
3 import { Checkbox } from "@kareyes/aether";
4
5 let indeterminateState = $state(false);
6</script>
7
8<Checkbox
9 bind:indeterminate={indeterminateState}
10 label="Partially selected"
11 description="This checkbox is in an indeterminate state"
12/>Todo List Example
1
2<script lang="ts">
3 import { Checkbox } from "@kareyes/aether";
4
5 let todos = $state([
6 { id: 1, text: "Complete project setup", completed: true },
7 { id: 2, text: "Design components", completed: true },
8 { id: 3, text: "Implement checkbox variants", completed: false },
9 { id: 4, text: "Write documentation", completed: false },
10 { id: 5, text: "Test in different browsers", completed: false },
11 ]);
12</script>
13
14<div class="space-y-3 bg-card p-6 rounded-lg border">
15 {#each todos as todo (todo.id)}
16 <Checkbox
17 bind:checked={todo.completed}
18 label={todo.text}
19 lineThrough={true}
20 size="default"
21 class="w-full"
22 />
23 {/each}
24</div>
25
26<div class="text-sm text-muted-foreground">
27 Completed: {todos.filter(t => t.completed).length} / {todos.length}
28</div>Error States
This checkbox must be checked
Invalid selection detected
1
2<script lang="ts">
3 import { Checkbox } from "@kareyes/aether";
4</script>
5
6<div class="space-y-4">
7 <Checkbox
8 error={true}
9 label="Checkbox with Error"
10 description="This checkbox must be checked"
11 onError={(err) => console.log('Error state:', err)}
12 />
13 <Checkbox
14 variant="destructive"
15 error={true}
16 checked={true}
17 label="Error with Destructive Variant"
18 description="Invalid selection detected"
19 />
20 <Checkbox
21 size="lg"
22 error={true}
23 label="Large Error Checkbox"
24 />
25</div>With Field Component
Field component provides structured labels, descriptions, and error handling
Single Checkbox with Field
Please review and accept our policies
With Validation
Multiple Checkboxes with Field.Set
1
2<script lang="ts">
3 import { Checkbox, Field, FieldPrimitives } from "@kareyes/aether";
4
5 let withLabelChecked = $state(false);
6 let basicChecked = $state(false);
7 let withDescriptionChecked = $state(false);
8 let successChecked = $state(false);
9</script>
10
11<!-- Single Checkbox with Field -->
12<Field
13 label="Agreements"
14 description="Please review and accept our policies"
15 required
16>
17 <Checkbox
18 label="I accept the terms and conditions"
19 bind:checked={withLabelChecked}
20 />
21</Field>
22
23<!-- With Validation -->
24<Field
25 label="Privacy Policy"
26 description="You must accept to continue"
27 required
28 error={!basicChecked ? "Please accept the privacy policy" : undefined}
29>
30 <Checkbox
31 label="I accept the privacy policy"
32 bind:checked={basicChecked}
33 error={!basicChecked}
34 />
35</Field>
36
37<!-- Multiple Checkboxes with FieldPrimitives.Set -->
38<FieldPrimitives.Set>
39 <FieldPrimitives.Legend>Email Preferences</FieldPrimitives.Legend>
40 <FieldPrimitives.Description>Choose which emails you'd like to receive</FieldPrimitives.Description>
41 <FieldPrimitives.Separator />
42 <FieldPrimitives.Group class="gap-4">
43 <Checkbox label="Notifications" variant="default" bind:checked={withDescriptionChecked} />
44 <Checkbox label="Marketing Emails" variant="default" checked={false} />
45 <Checkbox label="Product Updates" variant="success" bind:checked={successChecked} />
46 </FieldPrimitives.Group>
47</FieldPrimitives.Set>Disabled States
This checkbox is disabled
This checkbox is disabled and checked
1
2<script lang="ts">
3 import { Checkbox } from "@kareyes/aether";
4</script>
5
6<div class="space-y-4">
7 <Checkbox
8 checked={false}
9 disabled
10 label="Disabled unchecked"
11 description="This checkbox is disabled"
12 />
13 <Checkbox
14 checked={true}
15 disabled
16 label="Disabled checked"
17 description="This checkbox is disabled and checked"
18 />
19</div>Features
- ✅ Multiple Sizes: sm, default, lg, xl
- ✅ Color Variants: default, destructive, success, warning
- ✅ Labels & Descriptions: Built-in label and description support
- ✅ Line Through: Strike-through text when checked (great for todo lists)
- ✅ Indeterminate State: Partial selection support
- ✅ Full Accessibility: Proper ARIA attributes and keyboard navigation
- ✅ TypeScript Support: Complete type definitions
Basic Usage
Simple Checkbox
<script>
let checked = $state(false);
</script>
<Checkbox bind:checked />
With Label
<Checkbox
bind:checked
label="Accept terms and conditions"
/>
With Label and Description
<Checkbox
bind:checked
label="Enable notifications"
description="Get notified about updates and new features"
/>
Sizes
Available sizes: sm, default, lg, xl
<Checkbox size="sm" label="Small" />
<Checkbox size="default" label="Default" />
<Checkbox size="lg" label="Large" />
<Checkbox size="xl" label="Extra Large" />
Variants
Available variants: default, destructive, success, warning
<Checkbox
variant="destructive"
label="Delete all data"
description="This action cannot be undone"
/>
<Checkbox
variant="success"
label="Mark as completed"
/>
<Checkbox
variant="warning"
label="Proceed with caution"
/>
Line Through Feature
Perfect for todo lists and task management:
<Checkbox
bind:checked
lineThrough={true}
label="Complete project setup"
description="Set up development environment"
/>
When lineThrough is true and the checkbox is checked:
- Label text gets
line-throughdecoration - Text color changes to muted
- Description also gets line-through effect
Indeterminate State
For partial selections (like "select all" checkboxes):
<script>
let indeterminate = $state(true);
</script>
<Checkbox
bind:indeterminate
label="Select all items"
/>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
checked |
boolean |
false |
Checkbox checked state |
indeterminate |
boolean |
false |
Indeterminate state (partial selection) |
size |
'sm' | 'default' | 'lg' | 'xl' |
'default' |
Checkbox size |
variant |
'default' | 'destructive' | 'success' | 'warning' |
'default' |
Color variant |
label |
string |
undefined |
Label text |
description |
string |
undefined |
Description text |
lineThrough |
boolean |
false |
Strike through text when checked |
disabled |
boolean |
false |
Disable the checkbox |
class |
string |
undefined |
Additional CSS classes |
Examples
Todo List
<script>
let todos = $state([
{ id: 1, text: "Setup project", completed: true },
{ id: 2, text: "Design components", completed: false },
{ id: 3, text: "Write tests", completed: false },
]);
</script>
{#each todos as todo (todo.id)}
<Checkbox
bind:checked={todo.completed}
label={todo.text}
lineThrough={true}
/>
{/each}
Form with Validation
<script>
let acceptTerms = $state(false);
let newsletter = $state(false);
</script>
<div class="space-y-4">
<Checkbox
bind:checked={acceptTerms}
variant={acceptTerms ? "success" : "destructive"}
label="I accept the terms and conditions"
description="Required to create an account"
/>
<Checkbox
bind:checked={newsletter}
label="Subscribe to newsletter"
description="Get weekly updates about new features"
/>
</div>
Settings Panel
<script>
let settings = $state({
notifications: true,
darkMode: false,
autoSave: true,
});
</script>
<div class="space-y-6">
<Checkbox
bind:checked={settings.notifications}
size="lg"
label="Push Notifications"
description="Receive notifications on your device"
/>
<Checkbox
bind:checked={settings.darkMode}
size="lg"
label="Dark Mode"
description="Use dark theme across the application"
/>
<Checkbox
bind:checked={settings.autoSave}
size="lg"
variant="success"
label="Auto Save"
description="Automatically save your work every 30 seconds"
/>
</div>
Styling
The component uses Tailwind variants for consistent styling:
Size Classes
sm: 12px (size-3)default: 16px (size-4)lg: 20px (size-5)xl: 24px (size-6)
Variant Colors
default: Primary color schemedestructive: Red color scheme for dangerous actionssuccess: Green color scheme for positive actionswarning: Yellow color scheme for cautionary actions
Accessibility
- ✅ Proper ARIA attributes
- ✅ Keyboard navigation support
- ✅ Focus management
- ✅ Screen reader compatible
- ✅ High contrast support
- ✅ Disabled state handling
Browser Support
Works in all modern browsers with full feature support.
Using Checkbox with Field Component
The Field component provides a consistent way to add labels, descriptions, and error handling to your Checkbox components. Note that Checkbox already has built-in label and description props, so Field is most useful for grouping multiple checkboxes or when you need the advanced Field features.
Basic Field Usage
<script>
import { Checkbox } from "@kareyes/aether";
import { Field } from "@kareyes/aether";
let acceptTerms = $state(false);
</script>
<Field
label="Agreements"
description="Please review and accept our policies"
required
>
<Checkbox
bind:checked={acceptTerms}
label="I accept the terms and conditions"
/>
</Field>
Checkbox Group with Field
<script>
import { Checkbox } from "@kareyes/aether";
import { FieldPrimitives } from "@kareyes/aether";
let notifications = $state(false);
let marketing = $state(false);
let updates = $state(false);
</script>
<FieldPrimitives.Set>
<FieldPrimitives.Legend>Email Preferences</FieldPrimitives.Legend>
<FieldPrimitives.Description>Choose which emails you'd like to receive</FieldPrimitives.Description>
<FieldPrimitives.Separator />
<FieldPrimitives.Group class="gap-4">
<Checkbox
bind:checked={notifications}
label="Notifications"
description="Receive notifications about account activity"
/>
<Checkbox
bind:checked={marketing}
label="Marketing Emails"
description="Get updates about new products and features"
/>
<Checkbox
bind:checked={updates}
label="Product Updates"
description="Stay informed about product improvements"
/>
</FieldPrimitives.Group>
</FieldPrimitives.Set>
With Error State
<script>
import { Checkbox } from "@kareyes/aether";
import { FieldPrimitives } from "@kareyes/aether";
let acceptTerms = $state(false);
let error = $derived(!acceptTerms);
</script>
<Field
label="Terms & Conditions"
required
error={error ? "You must accept the terms to continue" : undefined}
>
<Checkbox
bind:checked={acceptTerms}
label="I accept the terms and conditions"
variant={error ? "destructive" : "default"}
/>
</Field>
Multiple Checkboxes with Variants
<script>
import { Checkbox } from "@kareyes/aether";
import { FieldPrimitives } from "@kareyes/aether";
let tasks = $state({
design: false,
development: false,
testing: false,
deployment: true,
});
</script>
<FieldPrimitives.Set>
<FieldPrimitives.Legend>Project Checklist</FieldPrimitives.Legend>
<FieldPrimitives.Description>Track your project progress</FieldPrimitives.Description>
<FieldPrimitives.Separator />
<FieldPrimitives.Group class="gap-4">
<Checkbox
bind:checked={tasks.design}
label="Complete Design"
description="UI/UX design and mockups"
lineThrough={true}
variant="default"
/>
<Checkbox
bind:checked={tasks.development}
label="Development Phase"
description="Code implementation"
lineThrough={true}
variant="default"
/>
<Checkbox
bind:checked={tasks.testing}
label="Testing & QA"
description="Quality assurance testing"
lineThrough={true}
variant="warning"
/>
<Checkbox
bind:checked={tasks.deployment}
label="Deployment"
description="Deploy to production"
lineThrough={true}
variant="success"
/>
</FieldPrimitives.Group>
</FieldPrimitives.Set>
Complete Form with Field
<script>
import { Checkbox } from "@kareyes/aether";
import { FieldPrimitives } from "@kareyes/aether";
import { Button } from "@kareyes/aether";
let formData = $state({
acceptTerms: false,
ageConfirmation: false,
newsletter: false,
updates: false,
});
let hasError = $derived(!formData.acceptTerms || !formData.ageConfirmation);
function handleSubmit() {
if (!hasError) {
console.log("Form submitted:", formData);
}
}
</script>
<div class="w-full max-w-md space-y-6">
<FieldPrimitives.Set>
<FieldPrimitives.Legend>Account Setup</FieldPrimitives.Legend>
<FieldPrimitives.Description>Complete your account registration</FieldPrimitives.Description>
<FieldPrimitives.Separator />
<FieldPrimitives.Group class="gap-4">
<Field
label="Required Agreements"
required
error={!formData.acceptTerms ? "You must accept the terms" : undefined}
>
<Checkbox
bind:checked={formData.acceptTerms}
label="I accept the terms and conditions"
variant={!formData.acceptTerms ? "destructive" : "success"}
size="lg"
/>
</Field>
<Field
label="Age Verification"
required
error={!formData.ageConfirmation ? "Age confirmation required" : undefined}
>
<Checkbox
bind:checked={formData.ageConfirmation}
label="I confirm I am 18 years or older"
variant={!formData.ageConfirmation ? "destructive" : "success"}
size="lg"
/>
</Field>
<Field
label="Optional Subscriptions"
description="Choose which communications you'd like to receive"
>
<div class="space-y-2">
<Checkbox
bind:checked={formData.newsletter}
label="Subscribe to newsletter"
description="Weekly updates and tips"
/>
<Checkbox
bind:checked={formData.updates}
label="Product updates"
description="New features and improvements"
/>
</div>
</Field>
</FieldPrimitives.Group>
<div class="flex gap-4 pt-4">
<Button onclick={handleSubmit} disabled={hasError}>
Create Account
</Button>
<Button variant="outline" type="button">
Cancel
</Button>
</div>
</FieldPrimitives.Set>
</div>