Pallas UI
DocsComponents
Core Concepts
    • Introduction
    • Getting Started
    • Theming
    • Color Tokens
    • Spacing & Sizing
    • Layout Guide
    • AspectRatio
    • Box
    • Flex
    • Grid
    • Shapes
Previews
    • Accordion
    • Alert
    • Avatar
    • Badge
    • Breadcrumb
    • Button
    • Carousel
    • Checkbox
    • Combobox
    • Command
    • Date Picker
    • Form
    • Input
    • Input OTP
    • Label
    • MenuBar
    • Modal
    • Popover
    • Progress
    • Radio Group
    • Segmented
    • Select
    • Separator
    • Sheet
    • Sidebar
    • Skeleton
    • Slider
    • Spinner
    • Steps
    • Switch
    • Tabs
    • Textarea
    • Toast
    • Tooltip
    • Typography
  1. Components
  2. Switch

Switch

A control that allows the user to toggle between checked and not checked.

Installation

Install the following dependencies

npm install @radix-ui/react-switch

Copy and paste the following code into your project

'use client'
 
import * as SwitchPrimitive from '@radix-ui/react-switch'
import { cx } from '@styled-system/css'
import { styled } from '@styled-system/jsx'
import { switchRecipe } from '@styled-system/recipes'
import * as React from 'react'
 
const BaseSwitch = React.forwardRef<
  React.ElementRef<typeof SwitchPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof SwitchPrimitive.Root>
>(({ className, ...props }, ref) => {
  const styles = switchRecipe()
 
  return (
    <SwitchPrimitive.Root className={cx('peer', styles.root, className)} {...props} ref={ref}>
      <SwitchPrimitive.Thumb className={styles.thumb} />
    </SwitchPrimitive.Root>
  )
})
BaseSwitch.displayName = SwitchPrimitive.Root.displayName
 
export const Switch = styled(BaseSwitch)

Update the import paths to match your project setup

Usage

import { Switch } from '@/components/ui/switch'
<Switch />

Examples

Default

Disabled

With Form

Email Notifications

Receive emails about new products, features, and more.

Receive emails about your account security.

Built with ❤️ by the carbonteq team. The source code is available on GitHub.

© 2025 Pallas UI. All rights reserved.