Svelte Checkbox - Bitblue

Get started with the checkbox component to allow the user to select one or more options in the form of a square box available in multiple sizes and colors

The checkbox component can be used to receive one or more selected options from the user in multiple styles, sizes, colors, and variants.

For validated forms, use FormCheckbox inside a parent Form. FormCheckbox requires Form context.

Setup

<script>
	import { Checkbox } from '.';
</script>

Checkbox examples

Use this default example of a checkbox element in a checked, unchecked and indeterminate state.

<script>
	import { Checkbox } from '.';
</script>

<Checkbox>Default checkbox</Checkbox>
<Checkbox checked>Checked state</Checkbox>
<Checkbox indeterminate>Indeterminate state</Checkbox>

Disabled state

<script>
	import { Checkbox } from '.';
</script>

<Checkbox disabled>Disabled checkbox</Checkbox>
<Checkbox disabled checked>Disabled checked</Checkbox>
<Checkbox disabled indeterminate>Disabled indeterminate</Checkbox>

Alternative syntax

If you need separate control over the label and the checkbox you can use the verbose syntax, but then you need to take care about aligning manually.

<script>
	import {
		Checkbox,
		Table,
		TableHead,
		TableHeadCell,
		TableBody,
		TableBodyCell,
		Label,
		TableBodyRow
	} from '.';
</script>

<Table>
	<TableHead>
		<TableHeadCell>Left column</TableHeadCell>
		<TableHeadCell>Right column</TableHeadCell>
	</TableHead>
	<TableBody class="divide-y dark:divide-gray-700">
		<TableBodyRow class="divide-x rtl:divide-x-reverse dark:divide-gray-700">
			<TableBodyCell><Label for="checkbox1">Default checkbox</Label></TableBodyCell>
			<TableBodyCell><Label for="checkbox2">Disabled checkbox</Label></TableBodyCell>
		</TableBodyRow>
		<TableBodyRow class="divide-x rtl:divide-x-reverse dark:divide-gray-700">
			<TableBodyCell><Checkbox id="checkbox1" checked /></TableBodyCell>
			<TableBodyCell><Checkbox id="checkbox2" disabled /></TableBodyCell>
		</TableBodyRow>
	</TableBody>
</Table>

<Label color="red" class="mt-4 flex items-center font-bold italic">
	Label on the other side <Checkbox classes={{ div: 'ms-2' }} />
</Label>

Checkbox with a link

<script>
	import { Checkbox } from '.';
</script>

<Checkbox>
	I agree with the
	<a href="/" class="text-primary-600 dark:text-primary-500 ms-1 hover:underline"
		>terms and conditions</a
	>
	.
</Checkbox>

Helper text

<script>
	import { Checkbox, Helper } from '.';
</script>

<Checkbox aria-describedby="helper-checkbox-text">Free shipping via Bitblue</Checkbox>
<Helper id="helper-checkbox-text" class="ps-6"
	>For orders shipped from $25 in books or $29 in other categories</Helper
>

Bordered

<script>
	import { Checkbox } from '.';
</script>

<div class="rounded-sm border border-gray-200 dark:border-gray-700">
	<Checkbox classes={{ div: 'w-full p-4' }}>Default checkbox</Checkbox>
</div>
<div class="rounded-sm border border-gray-200 dark:border-gray-700">
	<Checkbox checked classes={{ div: 'w-full p-4' }}>Checked state</Checkbox>
</div>

Checkbox list group

<script>
	import { Checkbox, Listgroup } from '.';
</script>

<p class="mb-4 font-semibold text-gray-900 dark:text-white">Technology</p>
<Listgroup class="w-48">
	<li><Checkbox classes={{ div: 'p-3' }}>svelte</Checkbox></li>
	<li><Checkbox classes={{ div: 'p-3' }}>Vue JS</Checkbox></li>
	<li><Checkbox classes={{ div: 'p-3' }}>React</Checkbox></li>
	<li><Checkbox classes={{ div: 'p-3' }}>Angular</Checkbox></li>
</Listgroup>

You can use the internal loop to render a list of CheckboxItems.

<script>
	import { Checkbox, Listgroup } from '.';
	let choices = [
		{ value: 'svelte', label: 'svelte' },
		{ value: 'vue', label: 'Vue JS' },
		{ value: 'react', label: 'React', checked: true },
		{ value: 'angular', label: 'Angular' }
	];
	let group = $state([]);
</script>

<p class="my-2">Choices: {group.join(', ')}</p>
<Listgroup class="w-48">
	<Checkbox bind:group {choices} classes={{ div: 'p-3' }} />
</Listgroup>

Horizontal list group

<script>
	import { Checkbox } from '.';
</script>

<p class="mb-4 font-semibold text-gray-900 dark:text-white">Identification</p>
<ul
	class="w-full items-center divide-x divide-gray-200 rounded-lg border border-gray-200 sm:flex rtl:divide-x-reverse dark:divide-gray-600 dark:border-gray-600 dark:bg-gray-800"
>
	<li class="w-full"><Checkbox classes={{ div: 'p-3' }}>Svelte</Checkbox></li>
	<li class="w-full"><Checkbox classes={{ div: 'p-3' }}>Vue JS</Checkbox></li>
	<li class="w-full"><Checkbox classes={{ div: 'p-3' }}>React</Checkbox></li>
	<li class="w-full"><Checkbox classes={{ div: 'p-3' }}>Angular</Checkbox></li>
</ul>

Inline layout

<script>
	import { Checkbox } from '.';
</script>

<div class="flex gap-3">
	<Checkbox>Inline 1</Checkbox>
	<Checkbox>Inline 2</Checkbox>
	<Checkbox checked>Inline checked</Checkbox>
	<Checkbox disabled>Inline disabled</Checkbox>
</div>

Or use the inline prop:

<script>
	import { Checkbox } from '.';
</script>

<Checkbox inline classes={{ div: 'me-2' }}>Inline 1</Checkbox>
<Checkbox inline classes={{ div: 'me-2' }}>Inline 2</Checkbox>
<Checkbox inline classes={{ div: 'me-2' }} checked>Inline checked</Checkbox>
<Checkbox inline classes={{ div: 'me-2' }} disabled>Inline disabled</Checkbox>

Colors

Theme colors: primary, secondary, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose.

<script>
	import { Label, Checkbox } from '.';
</script>

<div class="flex flex-col gap-4 sm:flex-row">
	<Checkbox checked color="red">Red</Checkbox>
	<Checkbox checked color="green">Green</Checkbox>
	<Checkbox checked color="purple">Purple</Checkbox>
	<Checkbox checked color="teal">Teal</Checkbox>
	<Checkbox checked color="yellow">Yellow</Checkbox>
	<Checkbox checked color="orange">Orange</Checkbox>
	<Label class="flex items-center">
		<Checkbox checked inline class="text-sky-400 focus:ring-pink-500" />
		Your custom color
	</Label>
</div>

CheckboxButton

CheckboxButton is a checkbox with Button styling. Use standalone or inside ButtonGroup.

<script>
	import { ButtonGroup, CheckboxButton } from '.';
	import { AppleSolid, FacebookSolid, DiscordSolid, DropboxSolid } from '.-icons';
	let group = $state([]);
</script>

<div>
	<CheckboxButton bind:group value="Apple"><AppleSolid class="me-2 h-6 w-6" />Apple</CheckboxButton>
	<CheckboxButton bind:group value="Facebook"
		><FacebookSolid class="me-2 h-6 w-6" />Facebook</CheckboxButton
	>
	<CheckboxButton bind:group value="Discord"
		><DiscordSolid class="me-2 h-6 w-6" />Discord</CheckboxButton
	>
	<CheckboxButton bind:group value="Dropbox"
		><DropboxSolid class="me-2 h-6 w-6" />Dropbox</CheckboxButton
	>
</div>

<ButtonGroup>
	<CheckboxButton bind:group value="Apple"><AppleSolid class="h-6 w-6" />Apple</CheckboxButton>
	<CheckboxButton bind:group value="Facebook"
		><FacebookSolid class="h-6 w-6" />Facebook</CheckboxButton
	>
	<CheckboxButton bind:group value="Discord"
		><DiscordSolid class="h-6 w-6" />Discord</CheckboxButton
	>
	<CheckboxButton bind:group value="Dropbox"
		><DropboxSolid class="h-6 w-6" />Dropbox</CheckboxButton
	>
</ButtonGroup>

Advanced layout

<script>
	import { Checkbox } from '.';
	import React from '../../utils/icons/React.svelte';
	import Vue from '../../utils/icons/Vue.svelte';
	import Angular from '../../utils/icons/Angular.svelte';
</script>

<p class="mb-5 text-lg font-medium text-gray-900 dark:text-white">Choose technology:</p>
<div class="grid w-full gap-6 md:grid-cols-3">
	<Checkbox custom>
		<div
			class="peer-checked:border-primary-600 w-full cursor-pointer rounded-lg border-2 border-gray-200 bg-white p-5 font-normal text-gray-500 peer-checked:text-gray-600 hover:bg-gray-50 hover:text-gray-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:peer-checked:text-gray-300 dark:hover:bg-gray-700 dark:hover:text-gray-300"
		>
			<React />
			<div class="w-full text-lg font-semibold">React Js</div>
			<div class="w-full text-sm">A JavaScript library for building user interfaces.</div>
		</div>
	</Checkbox>
	<Checkbox custom>
		<div
			class="peer-checked:border-primary-600 w-full cursor-pointer rounded-lg border-2 border-gray-200 bg-white p-5 font-normal text-gray-500 peer-checked:text-gray-600 hover:bg-gray-50 hover:text-gray-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:peer-checked:text-gray-300 dark:hover:bg-gray-700 dark:hover:text-gray-300"
		>
			<Vue />
			<div class="w-full text-lg font-semibold">Vue Js</div>
			<div class="w-full text-sm">Vue.js is a model–view front end JavaScript framework.</div>
		</div>
	</Checkbox>
	<Checkbox custom>
		<div
			class="peer-checked:border-primary-600 w-full cursor-pointer rounded-lg border-2 border-gray-200 bg-white p-5 font-normal text-gray-500 peer-checked:text-gray-600 hover:bg-gray-50 hover:text-gray-600 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:peer-checked:text-gray-300 dark:hover:bg-gray-700 dark:hover:text-gray-300"
		>
			<Angular />
			<div class="w-full text-lg font-semibold">Angular</div>
			<div class="w-full text-sm">A TypeScript-based web application framework.</div>
		</div>
	</Checkbox>
</div>

Group variable

<script>
	import { Button, Checkbox } from '.';
	let choices = [
		{ value: '1', label: 'One' },
		{ value: '2', label: 'Two' },
		{ value: '3', label: 'Three' }
	];
	let group = $state(['2', '3']);
</script>

<div class="flex gap-2">
	<Checkbox name="flavours" {choices} bind:group />
</div>
<div class="my-2 w-44 rounded-lg border border-gray-200 p-2 dark:border-gray-700 dark:text-gray-400">
	Group: {group}
</div>
<Button onclick={() => (group.length = 0)}>Clear</Button>

Accessibility

  • Labels wrap or associate via id / for.
  • Use aria-describedby for helper text.
  • indeterminate reflects mixed selection state for groups.
  • Prefer visible labels; do not rely on color alone.

Props

Checkbox

PropTypeDefaultDescription
childrenSnippet—Label content (or custom card when custom)
checkedboolean—Checked state (bindable)
indeterminateboolean—Indeterminate state
colortheme color—Accent color token
customboolean—Custom label layout (peer styling)
inlineboolean—Inline flex layout
tinted / roundedboolean—Visual variants
group(string \| number)[]—Bindable multi-select group
choicesCheckboxItem[]—Render multiple items into group
divClassClassValue—Wrapper classes
labelPropsRecord<string, any>—Extra props for label
classestheme slots—Slot class overrides (div, base, …)
disabled / name / value / idnative—HTML input attrs

CheckboxItem: { value: string | number; label?: string; checked?: boolean | null; ... }

CheckboxButton

PropTypeDefaultDescription
group(string \| number)[]—Bindable selected values
valuestring | number—This button’s value
checkedboolean—Standalone checked state
inlineboolean—Inline layout
pill / outline / shadowboolean—Button look
sizeButton size—Button size
colorButton color—Button color
...restHTML input attrs—Native attrs

FormCheckbox

FormCheckbox extends CheckboxProps with required name, optional label, contextKey, and onChange. Must be a child of Form.


© 2026 Bitblue is a registered trademark. All Rights Reserved.