Checkbox
A labeled boolean. Links inside the label stay independent.
Not agreed
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import CheckboxExample from './CheckboxExample.svelte';
</script>
<CheckboxExample invalid={false} disabled={false} required={false} />
<script lang="ts">
import { Checkbox } from 'portal-bits';
let {
invalid = false,
disabled = false,
required = false,
}: { invalid?: boolean; disabled?: boolean; required?: boolean } = $props();
let agreed = $state(false);
</script>
<div class="field">
<Checkbox
bind:checked={agreed}
{invalid}
{required}
{disabled}
aria-describedby={invalid ? 'terms-error' : undefined}
>
{#snippet label()}I agree to the <a href="#terms">demo terms</a>.{/snippet}
</Checkbox>
{#if invalid}
<p id="terms-error" class="error">Agree to the demo terms to continue.</p>
{/if}
<p aria-live="polite">{agreed ? 'Agreed' : 'Not agreed'}</p>
</div>
<style>
.field {
max-width: 340px;
}
.error {
color: var(--portal-error);
}
</style>
API reference
These tables list the props and snippets that Checkbox declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
checked | boolean | false | No | Bindable | The checked state. |
invalid | boolean | false | No | One-way | Sets `aria-invalid`. Render the error text yourself. |
id | string | Generated id | No | One-way | The control id. A stable id is generated when you omit it. |
name | string | None | No | One-way | Submits the checked value under this name. Unchecked boxes submit nothing. |
required | boolean | false | No | One-way | Takes part in native form validation, even without `name`. |
disabled | boolean | false | No | One-way | Disables the box only. Links in the label stay usable. |
form | string | None | No | One-way | The id of the form that owns the control. |
class | string | "" | No | One-way | Extra classes, added after the component classes. |
Snippets
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
label | Snippet | None | Yes | One-way | The label content. It may contain links, which stay independent. |
Forwarded attributes
- Bits UI `Checkbox.Root` props except `children`, `child`, `indeterminate`, and `onIndeterminateChange`: `value`, `readonly`, `onCheckedChange`, `ref`, native button attributes, and handlers.
The primitive underneath is a Bits UI peer dependency. Its own options are documented in the Bits UI Checkbox documentation. Only the props listed on this page are part of the Checkbox contract. No data attributes are documented as stable.
Limits
- No indeterminate state, description text, or option groups.
- Checkbox is an adaptation. Its dimensions and behavior were not measured.