Skip to content

CheckboxToggle

Toggle switch with sliding pill animation. Semantically a switch (role=“switch”) with optional label and press animation on the thumb.

import { CheckboxToggle } from "phoundry-ui";

Basic toggle

Loading interactive example…

View source
basic-toggle.svelte
<script lang="ts">
import { CheckboxToggle } from "phoundry-ui";
let basic = $state(false);
</script>
<div class="flex items-center gap-3">
<CheckboxToggle checked={basic} onchange={() => (basic = !basic)} />
<span class="text-xs text-txt-tertiary">{basic ? "On" : "Off"}</span>
</div>

With label

Loading interactive example…

View source
with-label.svelte
<script lang="ts">
import { CheckboxToggle } from "phoundry-ui";
let withLabel = $state(true);
let withDesc = $state(false);
</script>
<div class="flex flex-col gap-3">
<CheckboxToggle
checked={withLabel}
onchange={() => (withLabel = !withLabel)}
label="Auto-save enabled"
/>
<CheckboxToggle
checked={withDesc}
onchange={() => (withDesc = !withDesc)}
label="Enable notifications"
description="Receive push notifications for important events"
/>
</div>

Sizes

Loading interactive example…

View source
sizes.svelte
<script lang="ts">
import { CheckboxToggle } from "phoundry-ui";
let sizeSm = $state(true);
let sizeMd = $state(false);
</script>
<div class="flex flex-col gap-3">
<CheckboxToggle
checked={sizeSm}
onchange={() => (sizeSm = !sizeSm)}
size="sm"
label="Small (default)"
/>
<CheckboxToggle
checked={sizeMd}
onchange={() => (sizeMd = !sizeMd)}
size="md"
label="Medium"
/>
</div>

Snippet label

Loading interactive example…

View source
snippet-label.svelte
<script lang="ts">
import { CheckboxToggle } from "phoundry-ui";
let richLabelToggle = $state(true);
</script>
{#snippet promo()}
Accept <span class="font-medium text-accent-secondary">beta features</span>
{/snippet}
<CheckboxToggle
checked={richLabelToggle}
onchange={() => (richLabelToggle = !richLabelToggle)}
label={promo}
description="Pass a snippet when the label needs inline formatting."
/>

Disabled

Loading interactive example…

View source
disabled.svelte
<script lang="ts">
import { CheckboxToggle } from "phoundry-ui";
let disabled = $state(false);
</script>
<div class="flex flex-col gap-3">
<CheckboxToggle checked={true} disabled label="Disabled (on)" />
<CheckboxToggle checked={disabled} disabled label="Disabled (off)" />
</div>

API

From phoundry-ui@0.4.21

NameTypeDefaultDescription
checkedrequiredboolean—Whether the toggle is on
onchange() => void—Called when the toggle is flipped
disabledbooleanfalsePrevents interaction
size"xs" | "sm" | "md"'sm'Size of the toggle track and thumb
labelstring | Snippet<[]>—Inline label rendered next to the toggle
descriptionstring—Helper text below the label
classClassValue—Additional CSS classes
stylestring—Inline styles on the component styling target described below.
idstring—Element id (auto-generated if omitted)
namestring—Form field name - renders a hidden input
elementbindableHTMLButtonElement—Bindable reference to the switch button.

Other native attributes: Forwarded to the <button> (e.g. aria-describedby).

Usage tips

  • Use for boolean settings that take effect immediately (e.g. dark mode, notifications).
  • Prefer Checkbox over CheckboxToggle when the value is part of a form that requires explicit submission.
  • The thumb has a press animation - users get tactile feedback on click.
  • Pass a name prop for native form submission via hidden input.

Styling

.ph-toggle is the stable root identification hook. Styling is component-local vanilla CSS; data-size always identifies the selected size. The root is the label wrapper when labelled and the switch button otherwise. class and style apply to that root; native attributes, attachments, and bind:element still target the button. Sizes remain xs, sm, and md. --ph-toggle-thumb-shadow controls the thumb shadow. Press and slide transitions respect reduced-motion preferences. Internal part selectors and --_ph-* properties are implementation details. Filled indicators use the active Theme’s --text-on-accent foreground.

Documentation is licensed under CC BY 4.0. Phoundry names and marks remain reserved.