UIPin
ComponentsIconsIllustrationsMotionTemplatesApps
Boards
UIPin

Free, open-source UI components, icons, illustrations, motion, templates and apps, in one search. Every item links to its source and licence.

UIPin is free. If it saved you time, you can keep it running:

Buy me a coffee
ComponentsIconsIllustrationsMotionTemplatesAppsLibrariesCompareNew this weekMCP for agentsBoardsPrivacy

Components, icons and artwork belong to their authors and are shown under their open-source licences.

shadcn/ui/Switch

Inputs & forms
1 of 3
Compiling

Theme it

Every preview, live

Brand colour

Corner radius

Font

Recolours shadcn’s tokens, Tailwind’s accent colours and colours set in the code. Red, amber and green classes stay, since they usually mean error, warning or success.

3 versions·3 librariesCompare all switches →

  • shadcn/ui
  • 8bitcn
  • Kokonut UI

Switch

npx shadcn@latest add https://ui.shadcn.com/r/styles/new-york-v4/switch.json
Open in v0 Docs Repo
Library
shadcn/ui
License
MIT
Stack
React · Tailwind CSS · radix
Packages
cnradix-ui
Also adds
label
Size
35 lines
Demo
From shadcn/ui

Code

registry/new-york-v4/ui/switch.tsx

"use client"

import * as React from "react"
import { cn } from "cn"
import { Switch as SwitchPrimitive } from "radix-ui"

function Switch({
  className,
  size = "default",
  ...props
}: React.ComponentProps<typeof SwitchPrimitive.Root> & {
  size?: "sm" | "default"
}) {
  return (
    <SwitchPrimitive.Root
      data-slot="switch"
      data-size={size}
      className={cn(
        "peer group/switch inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[1.15rem] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80",
        className
      )}
      {...props}
    >
      <SwitchPrimitive.Thumb
        data-slot="switch-thumb"
        className={cn(
          "pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground"
        )}
      />
    </SwitchPrimitive.Root>
  )
}

export { Switch }

More like this

Theme Toggler

Magic UI·Buttons

Side Panel

Cult UI·Other

Sheet

shadcn/ui·Overlays

Toolbar Dynamic

Motion Primitives·Navigation

Button

shadcn/ui·Buttons

Toolbar Expandable

Motion Primitives·Navigation

Carousel

HextaUI·Media & 3D

Dropdown Menu

shadcn/ui·Overlays

Progress

HextaUI·Feedback & loaders

Skeleton

shadcn/ui·Feedback & loaders

Border Trail

Motion Primitives·Cursor & effects

Input Otp

shadcn/ui·Inputs & forms

Logo Cloud 4

SmoothUI·Media & 3D

Iphone

Magic UI·Media & 3D

Slider

shadcn/ui·Inputs & forms