Forms Core Stable

Switch

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

Preview

Installation

pnpm add fancy-ui-svelte
import { Switch } from 'fancy-ui-svelte'

Usage

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

<Switch />

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
childrenVisible label text, rendered beside the track