Forms

Switch

Turns a single setting on or off, taking effect immediately.

Installation

npx sinaui add switch

Examples

Basic

A native checkbox underneath: it submits with its form as name=on.

<script lang="ts">
	import Switch from '#lib/ui/Switch.svelte';

	let notify = $state(true);
</script>

<form method="post">
	<Switch name="notify" bind:checked={notify}>Notify me of new translations</Switch>
</form>

Disabled

<script lang="ts">
	import Switch from '#lib/ui/Switch.svelte';
</script>

<Switch disabled>Lend to the Córdoba library</Switch>

Without a visible label

When the context makes it obvious, name it with aria-label instead.

<script lang="ts">
	import Switch from '#lib/ui/Switch.svelte';
</script>

<Switch aria-label="Observatory night mode" />

Props

PropTypeDefault
checkedboolean, bindablefalse
childrenSnippet: the visible label
…restAny <input> attribute (name, disabled, aria-label…).

Accessibility

  • A native checkbox with role="switch": form submission, reset and label clicks need no JavaScript.
  • The thumb, not the track, shows the state, with at least 3:1 contrast in both positions.
  • Use a switch for settings that apply immediately; use a checkbox for choices submitted with a form.
KeyAction
SpaceToggles the switch.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme