Checkbox
Toggle a boolean value on or off. Supports labels, descriptions, colors, sizes, list/card variants, indeterminate state, loading, and custom icons.
variant="card" checkbox is now named by its label, and its description is announced in both variants. Inside a FormField a card checkbox is named by the field label and its own, like the list variant. An aria-label or aria-labelledby you pass still wins.Playground
Experiment with different props in real-time.
Receive weekly updates
Basic Usage
Use bind:checked for two-way binding.
<script lang="ts">
import { Checkbox } from 'sv5ui';
let checked = $state(false);
</script>
<!-- No visible label, so name it with aria-label -->
<Checkbox bind:checked aria-label="Remember me" />Label & Description
Add context with label and description.
You agree to our Terms of Service and Privacy Policy.
Receive weekly updates about new features.
<Checkbox
label="Accept terms"
description="You agree to our Terms of Service and Privacy Policy."
bind:checked
/>
<Checkbox
label="Subscribe to newsletter"
description="Receive weekly updates about new features."
/>Variants
2 visual styles: list (default) and card.
Standard checkbox layout
Highlighted card-style layout
<!-- List variant (default) -->
<Checkbox variant="list" label="List variant" description="Standard checkbox layout" />
<!-- Card variant -->
<Checkbox variant="card" label="Card variant" description="Highlighted card-style layout" />Indicator Position
Control where the checkbox indicator appears.
<!-- Start (default) -->
<Checkbox indicator="start" label="Indicator at start" />
<!-- End -->
<Checkbox indicator="end" label="Indicator at end" />
<!-- Hidden -->
<Checkbox indicator="hidden" label="Hidden indicator" />Sizes
5 sizes.
<Checkbox size="xs" label="Extra Small" />
<Checkbox size="sm" label="Small" />
<Checkbox size="md" label="Medium" />
<Checkbox size="lg" label="Large" />
<Checkbox size="xl" label="Extra Large" />Colors
8 semantic color schemes.
<Checkbox color="primary" label="Primary" checked />
<Checkbox color="secondary" label="Secondary" checked />
<Checkbox color="tertiary" label="Tertiary" checked />
<Checkbox color="success" label="Success" checked />
<Checkbox color="warning" label="Warning" checked />
<Checkbox color="error" label="Error" checked />
<Checkbox color="info" label="Info" checked />
<Checkbox color="surface" label="Surface" checked />Indeterminate
Partial selection state with bind:indeterminate.
<script lang="ts">
import { Checkbox } from 'sv5ui';
let parentChecked = $state(false);
let indeterminate = $state(true);
</script>
<Checkbox
label="Select all"
bind:checked={parentChecked}
bind:indeterminate
/>Loading
Show a spinner instead of the icon.
<Checkbox loading label="Loading" />
<Checkbox loading checked label="Loading checked" />Disabled
Prevent interaction.
<Checkbox disabled label="Disabled" />
<Checkbox disabled checked label="Disabled checked" />Custom Icons
Replace the default check icon.
<Checkbox icon="lucide:heart" label="Favorite" checked color="error" />
<Checkbox icon="lucide:star" label="Starred" checked color="warning" />
<Checkbox icon="lucide:thumbs-up" label="Liked" checked color="info" />Card Group
Use card variant for option selection layouts.
5GB storage, basic features
50GB storage, advanced features
Unlimited storage, collaboration
Custom solutions, priority support
<script lang="ts">
import { Checkbox } from 'sv5ui';
</script>
<div class="grid gap-3 sm:grid-cols-2">
<Checkbox variant="card" label="Free Plan" description="5GB storage, basic features" />
<Checkbox variant="card" label="Pro Plan" description="50GB storage, advanced features" checked />
<Checkbox variant="card" label="Team Plan" description="Unlimited storage, collaboration" />
<Checkbox variant="card" label="Enterprise" description="Custom solutions, priority support" disabled />
</div>Accessibility
A checkbox with a label is named by it, and its description is announced, in both the list and the card variant. Content passed to labelSlot is not linked to the checkbox, so give it an aria-label as well. Without a label, as in a table row, pass aria-label. It lands on the checkbox itself, where assistive technology looks for it, along with the other naming and describing attributes: aria-label, aria-labelledby, aria-describedby, aria-invalid, aria-required, aria-errormessage and aria-details. class, style, data-* and aria-hidden stay on the wrapper.
<!-- No visible label, as in a table header: name it yourself -->
<Checkbox aria-label="Select all rows" />
<Checkbox aria-label="Select row 1" checked />onfocus and onblur are attached to the checkbox as well, and an onclick you pass runs on every click. Inside a FormField the field label names the checkbox and its description is announced.
UI Slots
Use the ui prop to override classes on internal elements.
| Slot | Description |
|---|---|
root | Outermost wrapper - controls overall layout and spacing |
base | Clickable checkbox area - controls focus ring, cursor, transitions |
container | Visual box holding the indicator - controls border, background, rounding |
indicator | Inner element shown when checked - controls check/indeterminate styling |
icon | Icon inside the indicator - controls icon size and color |
wrapper | Wraps label and description text - controls text layout |
label | Primary text label - controls font size, weight, color |
description | Secondary helper text - controls font size and opacity |
Snippets
| Snippet | Description |
|---|---|
labelSlot | Custom label rendering |
descriptionSlot | Custom description rendering |
Props
| Prop | Type | Default |
|---|---|---|
checked | boolean | false |
onCheckedChange | (checked) => void | - |
indeterminate | boolean | false |
onIndeterminateChange | (val) => void | - |
variant | 'list' | 'card' | 'list' |
indicator | 'start' | 'end' | 'hidden' | 'start' |
color | ColorType | 'primary' |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' |
label | string | - |
description | string | - |
icon | string | 'lucide:check' |
indeterminateIcon | string | 'lucide:minus' |
loading | boolean | false |
loadingIcon | string | icons.loading |
disabled | boolean | false |
required | boolean | false |
id | string | - |
name | string | - |
value | string | - |
ref | HTMLElement | null | null |
class | string | - |
ui | Record<Slot, Class> | - |