Kumo Svelte
  • Home
  • Installation
  • Colors
  • Accessibility
  • Changelog
  • Autocomplete
  • Badge
  • Banner
  • Breadcrumbs
  • Button
  • Checkbox
  • Clipboard Text
  • Cloudflare Logo
  • CodeHighlighted
  • Collapsible
  • Combobox
  • Command Palette
  • Date Picker
  • Dialog
  • Dropdown
  • Empty
  • Flow
  • Grid
  • Input
  • InputArea
  • InputGroup
  • Label
  • Layer Card
  • Link
  • Loader
  • MenuBar
  • Meter
  • Pagination
  • Popover
  • Radio
  • Select
  • Sensitive Input
  • Sidebar
  • Skeleton Line
  • Switch
  • Table
  • Table of Contents
  • Tabs
  • Text
  • Toast
  • Toolbar
  • Tooltip
  • Charts
  • Colors
  • Timeseries
  • Maps
  • Sankey
  • Custom Chart
  • Page Header
  • Resource List
  • Delete Resource
Switch
kumo-svelte

Switch

A two-state button that can be either on or off.

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
  let checked = $state(false);
</script>

<Switch.Root label="Switch" bind:checked />

Import

import * as Switch from "kumo-svelte/components/switch";

Usage

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
  let checked = $state(false);
</script>

<Switch.Root label="Switch" bind:checked />

Examples

Off State

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
</script>

<Switch.Root label="Switch" checked={false} />

On State

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
</script>

<Switch.Root label="Switch" checked />

Disabled

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
</script>

<Switch.Root label="Disabled" checked={false} disabled />

Variants

The Switch supports two variants: default (blue when on) and neutral (monochrome). Both use a squircle shape.

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
</script>

<div class="grid grid-cols-2 gap-x-8 gap-y-4">
  <Switch.Root label="Default off" checked={false} />
  <Switch.Root label="Default on" checked />
  <Switch.Root label="Neutral off" variant="neutral" checked={false} />
  <Switch.Root label="Neutral on" variant="neutral" checked />
</div>

Neutral Variant

The neutral variant uses monochrome colors and a squircle shape, ideal for subtle, less prominent toggles.

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
  let checked = $state(false);
</script>

<Switch.Root label="Neutral switch" variant="neutral" bind:checked />

Neutral States

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
</script>

<div class="flex flex-col gap-4">
  <Switch.Root label="Neutral off" variant="neutral" checked={false} />
  <Switch.Root label="Neutral on" variant="neutral" checked />
  <Switch.Root label="Neutral disabled" variant="neutral" checked={false} disabled />
</div>

Sizes

Three sizes available: sm, base (default), and lg.

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
</script>

<div class="flex flex-col gap-4">
  <Switch.Root label="Small" size="sm" checked />
  <Switch.Root label="Base (default)" size="base" checked />
  <Switch.Root label="Large" size="lg" checked />
</div>

Custom ID

When a custom id is provided, clicking the label still toggles the switch.

<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
  let checked = $state(false);
</script>

<Switch.Root id="my-custom-switch" label="Custom ID" bind:checked />

Switch Group

Group related switches with Switch.Group. Provides a shared legend, description, and error message for the group.

Notification settings
<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
</script>

<Switch.Group legend="Notification settings">
  <Switch.Item label="Email notifications" />
  <Switch.Item label="SMS notifications" />
  <Switch.Item label="Push notifications" />
</Switch.Group>

Visually Hidden Legend

Use Switch.Legend with class="sr-only" to keep the legend accessible to screen readers while hiding it visually.

Notification settings
<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
</script>

<Switch.Group>
  <Switch.Legend class="sr-only">Notification settings</Switch.Legend>
  <Switch.Item label="Email notifications" />
  <Switch.Item label="SMS notifications" />
  <Switch.Item label="Push notifications" />
</Switch.Group>

Custom Legend Styling

Switch.Legend accepts class for full control over legend presentation.

Notification settings
<script lang="ts">
  import * as Switch from "kumo-svelte/components/switch";
</script>

<Switch.Group>
  <Switch.Legend class="text-sm font-normal text-kumo-subtle">Notification settings</Switch.Legend>
  <Switch.Item label="Email notifications" />
  <Switch.Item label="SMS notifications" />
  <Switch.Item label="Push notifications" />
</Switch.Group>

API Reference

Switch

PropTypeDefault
checkedbooleanfalse
classstring—
controlFirstbooleantrue
disabledbooleanfalse
idstring—
labelSnippet | string—
labelTooltipSnippet—
namestring—
onCheckedChange(checked: boolean) => void—
requiredboolean—
sizeKumoSwitchSizeKUMO_SWITCH_DEFAULT_VARIANTS.size
transitioningboolean—
valuestring—
variantSwitchVariantKUMO_SWITCH_DEFAULT_VARIANTS.variant
aria-labelstring—
aria-labelledbystring—

Switch.Control

PropTypeDefault
checkedbooleanfalse
classstring—
disabledbooleanfalse
idstring—
namestring—
onCheckedChange(checked: boolean) => void—
requiredboolean—
sizeKumoSwitchSizeKUMO_SWITCH_DEFAULT_VARIANTS.size
transitioningboolean—
valuestring—
variantSwitchVariantKUMO_SWITCH_DEFAULT_VARIANTS.variant
aria-labelstring—
aria-labelledbystring—

Switch.Group

PropTypeDefault
children*Snippet—
classstring—
controlFirstbooleantrue
descriptionSnippet | string—
disabledbooleanfalse
errorstring—
legendstring—

Switch.Item

PropTypeDefault
checkedbooleanfalse
classstring—
disabledbooleanfalse
idstring—
label*Snippet | string—
onCheckedChange(checked: boolean) => void—
sizeKumoSwitchSizeKUMO_SWITCH_DEFAULT_VARIANTS.size
transitioningboolean—
variantSwitchVariantKUMO_SWITCH_DEFAULT_VARIANTS.variant

Switch.Legend

PropTypeDefault
children*Snippet—
classstring—

On this page

  • Import
  • Usage
  • Examples
    • Off State
    • On State
    • Disabled
    • Variants
    • Neutral Variant
    • Neutral States
    • Sizes
    • Custom ID
    • Switch Group
    • Visually Hidden Legend
    • Custom Legend Styling
  • API Reference
    • Switch
    • Switch.Control
    • Switch.Group
    • Switch.Item
    • Switch.Legend