Skip to content
portalbits
Home Docs GitHub(opens in a new tab)

Guides

Get startedFoundationsMotion

Components

All components

Buttons

ButtonIconButton

Inputs

InputSelectTextareaSlider

Selection

CheckboxToggleToggleGroupSwitchRadioGroup

Identity

AvatarBadge

Overlays

DialogPopoverTooltipDropdownMenuAlertDialog

Disclosure

TabsAccordion

Cards

AppCardArticleCardFeatureCard

Content

CarouselSectionHeaderEmptyStateAlertProgressSeparatorRowListRow

Chrome

PortalShellSidebarNavMobileNavTopBarAuthFrameColorSelectorFloatingNav

Switch

A labeled on or off switch, including a disabled state.

Notifications off
Variations

Source

<script lang="ts">
  import 'portal-bits/styles.css';
  import 'portal-bits/tokens.css';
  import type { Snippet } from 'svelte';

  let { children }: { children: Snippet } = $props();
</script>

{@render children()}
<script lang="ts">
  import SwitchExample from './SwitchExample.svelte';
</script>

<SwitchExample disabled={false} />
<script lang="ts">
  import { Switch } from 'portal-bits';
  let { disabled = false }: { disabled?: boolean } = $props();
  let checked = $state(false);
</script>

<div class="row">
  <Switch label="Enable notifications" bind:checked {disabled} />
  <span>Notifications {checked ? 'on' : 'off'}</span>
</div>

<style>
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
  }
</style>

API reference

These tables list the props and snippets that Switch declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.

Props

NameTypeDefaultRequiredBindingDescription
labelstringNoneYesOne-wayThe accessible name, set as `aria-label`.
checkedbooleanfalseNoBindableWhether the switch is on.

Forwarded attributes

  • Bits UI `Switch.Root` props except `children` and `child`: `disabled`, `required`, `name`, `value`, `onCheckedChange`, `ref`, native button attributes, and handlers.

The primitive underneath is a Bits UI peer dependency. Its own options are documented in the Bits UI Switch documentation. Only the props listed on this page are part of the Switch contract. No data attributes are documented as stable.

Limits

  • The label is not visible. Place a visible label next to the switch yourself.
  • The thumb and track markup are fixed.

Related

  • Checkbox
  • Toggle
Previous ToggleGroup Next RadioGroup

On this page

  • Preview
  • Source
  • API reference
  • Props
  • Forwarded attributes
  • Limits