Skip to content
Forms Core Stable

Switch

.md

A sliding on/off control that takes effect immediately, built on a native checkbox input

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { Switch } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import { Switch } from "fancy-ui-svelte";

	let notifications = $state(false);
</script>

<Switch sound bind:checked={notifications} label="Notifications" />

Examples

Basic Usage

A single switch with a bound checked state and no visible label text.

Sizes

The three available sizes, sm/md/lg.

With Label

Visible label text rendered beside the track via children.

Props

PropTypeDefaultDescription
checked booleanfalseWhether the switch is on; bindable
onCheckedChange (checked: boolean) => void-Called with the new value whenever the switch is activated
disabled booleanfalseBlocks interaction; excluded from form submission
required booleanfalseNative required
id string-Element id
name string-Native name, read on form submission
value string-Form value submitted while on
label string-Accessible name, rendered as aria-label; skip it when children already supplies the visible label text
size "sm" | "md" | "lg""md"Track/knob size
class string-Additional CSS classes, merged onto the wrapping label
ref HTMLInputElement | nullnullBindable element reference to the native input
sound booleanfalsePlays toggle-on or toggle-off on each change, once the user has enabled sound

Slots

SlotDescription
children Visible label text, rendered beside the track