Skip to content
portalbits
Home Docs GitHub(opens in a new tab)

Guides

Get startedFoundationsMotion

Components

All components

Buttons

ButtonIconButton

Inputs

InputSelectTextareaSlider

Selection

CheckboxToggleToggleGroupSwitchRadioGroup

Identity

AvatarBadge

Overlays

DialogPopoverTooltipDropdownMenuAlertDialog

Disclosure

TabsAccordion

Cards

AppCardArticleCardFeatureCard

Content

CarouselSectionHeaderEmptyStateAlertProgressSeparatorRowListRow

Chrome

PortalShellSidebarNavMobileNavTopBarAuthFrameColorSelectorFloatingNav

Checkbox

A labeled boolean. Links inside the label stay independent.

Not agreed

Variations

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

NameTypeDefaultRequiredBindingDescription
checkedbooleanfalseNoBindableThe checked state.
invalidbooleanfalseNoOne-waySets `aria-invalid`. Render the error text yourself.
idstringGenerated idNoOne-wayThe control id. A stable id is generated when you omit it.
namestringNoneNoOne-waySubmits the checked value under this name. Unchecked boxes submit nothing.
requiredbooleanfalseNoOne-wayTakes part in native form validation, even without `name`.
disabledbooleanfalseNoOne-wayDisables the box only. Links in the label stay usable.
formstringNoneNoOne-wayThe id of the form that owns the control.
classstring""NoOne-wayExtra classes, added after the component classes.

Snippets

NameTypeDefaultRequiredBindingDescription
labelSnippetNoneYesOne-wayThe 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.

Related

  • Switch
  • Toggle
Previous Slider Next Toggle

On this page

  • Preview
  • Source
  • API reference
  • Props
  • Snippets
  • Forwarded attributes
  • Limits