LayerwiseLayerwise
  • Features
  • Pricing
  • Templates
  • Docs
DownloadDownload
FeaturesPricingTemplatesDocsAI Website BuilderVibe CodingPersonal Software
DownloadDownload
  1. Glossary
  2. /
  3. Components

Toggle switch

Also called switch or toggle

An on/off control shaped like a small track with a sliding knob, used for settings that take effect immediately.

import { useState } from 'react';
import { Switch } from '@base-ui/react/switch';

const SETTINGS = [
  { id: 'mentions', label: 'Mentions', hint: 'When someone @mentions you' },
  { id: 'comments', label: 'Comments', hint: 'Replies on files you own' },
  { id: 'summary', label: 'Weekly summary', hint: 'Every Monday at 9 AM' }
];

type Props = { onChange: (id: string, on: boolean) => Promise<void> };

export function NotificationSettings({ onChange }: Props) {
  const [enabled, setEnabled] = useState<Record<string, boolean>>({
    mentions: true
  });

  function toggle(id: string, on: boolean) {
    // Optimistic: flip right away, and flip back if saving fails.
    setEnabled((current) => ({ ...current, [id]: on }));
    onChange(id, on).catch(() =>
      setEnabled((current) => ({ ...current, [id]: !on }))
    );
  }

  return (
    <ul className='w-96 divide-y rounded-xl border'>
      {SETTINGS.map(({ id, label, hint }) => (
        <li key={id}>
          {/* The wrapping label makes the whole row toggle the switch. */}
          <label className='flex cursor-pointer items-center justify-between gap-4 px-4 py-3'>
            <span>
              <span className='block text-sm font-medium'>{label}</span>
              <span className='text-sm text-muted-foreground'>{hint}</span>
            </span>
            <Switch.Root
              checked={enabled[id] ?? false}
              onCheckedChange={(on) => toggle(id, on)}
              className='flex h-6 w-11 shrink-0 rounded-full bg-muted-foreground/30 p-0.5 transition-colors duration-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring data-checked:bg-blue-600'
            >
              {/* A curve that overshoots slightly gives the knob a springy settle. */}
              <Switch.Thumb className='size-5 rounded-full bg-white shadow-sm transition-transform duration-200 ease-[cubic-bezier(0.34,1.56,0.64,1)] data-checked:translate-x-5 motion-reduce:transition-none' />
            </Switch.Root>
          </label>
        </li>
      ))}
    </ul>
  );
}
Build the notification settings as a list of toggle switches: a 44×24px track with a 20px knob that slides with a spring (stiffness 500, damping 30) while the track fades from gray to blue over 200ms. Save each change right away with an optimistic update, make the whole row clickable, use role='switch' with aria-checked, and skip the slide when prefers-reduced-motion is set.

Paste into Layerwise or any AI coding tool.

What is Toggle switch?

A toggle switch mimics a physical switch: a pill-shaped track with a round knob that slides from one end to the other. The track changes color with it, usually gray for off and an accent color for on, so the state reads at a glance.

Use a switch for a setting that applies right away, like push notifications or dark mode. If the choice only takes effect after someone presses Save, a checkbox is clearer. Label the switch with the thing it controls, such as Weekly summary, and let the knob show whether it is on.

A small spring makes the knob feel physical: a quick slide of 150 to 250ms with only a hint of overshoot. Use role='switch' with aria-checked, or a native checkbox styled as a switch, make the whole row clickable, and rely on the knob's position as well as color to show the state.

Often confused with

Checkbox
A checkbox suits choices that apply when a form is submitted, or selecting several items. A switch applies a setting the moment you flip it.

Related terms

All terms

Checkbox

A small square you tick to turn an option on or select an item, with a dash in a parent box when only some items are checked.

Spring animation

An animation driven by simulated spring physics in place of a fixed duration and curve, so motion can overshoot, settle, and react naturally.

Optimistic UI

A pattern where the interface shows the result of an action right away, before the server confirms it, and rolls it back if the request fails.

Micro-interaction

A small moment of feedback around a single action, like a heart that bursts when tapped or a copy icon that turns into a checkmark.

Build it with Layerwise

Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.

DownloadDownloadRead the docs
LayerwiseLayerwise

Build full-stack web apps in minutes with AI.

Product

  • Features
  • Pricing
  • Download
  • Templates

Solutions

  • AI Website Builder
  • Vibe Coding
  • Personal Software

Resources

  • Documentation
  • Changelog
  • Blog
  • Vibe Coding Glossary
  • llms.txt
  • llms-full.txt

Company

  • About
  • Contact

Legal

  • Privacy
  • Analytics Privacy
  • Terms
  • Security
  • Abuse

© 2026 Layerwise. All rights reserved.

Entrances & exits

  • Fade in
  • Slide in
  • Scale in
  • Pop in
  • Blur in
  • Reveal animation
  • Enter and exit animations

Timing & sequencing

  • Duration
  • Delay
  • Keyframes
  • Tweening
  • Stagger
  • Orchestration
  • Fill mode
  • Stepped animation
  • Looping animation
  • Yoyo animation

Easing

  • Easing
  • Linear easing
  • Ease-in
  • Ease-out
  • Ease-in-out
  • Cubic-bezier
  • Asymmetric easing
  • Overshoot easing

Springs & physics

  • Spring animation
  • Stiffness
  • Damping
  • Mass
  • Bounce
  • Velocity
  • Momentum
  • Interruptible animation
  • Rubber-banding

Transforms

  • Translate
  • Scale
  • Rotate
  • Skew
  • 3D flip
  • Perspective
  • Transform origin
  • Origin-aware animation

State transitions

  • Crossfade
  • Morph
  • Shared element transition
  • Layout animation
  • Height auto animation
  • Direction-aware transition
  • Continuity transition
  • Page transition
  • View Transitions API

Scroll effects

  • Scroll reveal
  • Scroll-driven animation
  • Parallax scrolling
  • Scrollytelling
  • Scroll pinning
  • Horizontal scroll section
  • Scroll progress bar
  • Scroll snap
  • Smooth scrolling

Interaction feedback

  • Hover effect
  • Press feedback
  • Ripple effect
  • Shake animation
  • Hold to confirm
  • Drag gesture
  • Drag to reorder
  • Swipe to dismiss
  • Pull to refresh
  • Magnetic button
  • Custom cursor
  • 3D tilt card
  • Spotlight card

Text effects

  • Typewriter effect
  • Text scramble
  • Split text animation
  • Text morph
  • Rotating words
  • Gradient text
  • Shimmer text
  • Number ticker
  • Tabular numbers
  • Underline animation

Loops & ambient motion

  • Marquee
  • Pulse animation
  • Float animation
  • Orbit animation
  • Idle animation
  • Particle background
  • Border beam
  • Confetti
  • Animated gradient

Visual effects

  • Blur
  • Clip-path
  • Mask
  • Before/after slider
  • SVG line drawing
  • Lottie animation

Motion principles

  • Purposeful animation
  • Anticipation
  • Follow-through
  • Squash and stretch
  • Perceived performance
  • Frequency of use
  • Spatial consistency
  • Reduced motion

Animation performance

  • Frame rate (FPS)
  • Jank
  • GPU acceleration
  • will-change
  • Layout thrashing

Layout

  • Hero section
  • Above the fold
  • Sticky header
  • Sidebar
  • Bento grid
  • Card
  • Flexbox
  • CSS Grid
  • Padding vs margin
  • Responsive design
  • Container
  • Masonry layout
  • Split screen
  • Z-index
  • Overflow

Components

  • Button variants
  • Modal
  • Drawer
  • Popover
  • Tooltip
  • Dropdown menu
  • Context menu
  • Toast notification
  • Tabs
  • Segmented control
  • Accordion
  • Carousel
  • Command palette
  • Combobox
  • Toggle switch
  • Checkbox
  • Radio button
  • Date picker
  • Breadcrumb
  • Pagination
  • Infinite scroll
  • Badge
  • Avatar stack
  • Empty state
  • Skeleton screen
  • Spinner
  • Progress bar
  • Data table
  • Stepper
  • Floating label
  • Inline validation
  • Alert banner
  • Tag input

States & patterns

  • Interaction states
  • Focus ring
  • Loading state
  • Optimistic UI
  • Debounce
  • Lazy loading
  • Dark mode
  • Micro-interaction
  • Affordance
  • Undo
  • Drag and drop
  • Keyboard shortcut

Visual styles

  • Glassmorphism
  • Liquid glass
  • Neumorphism
  • Claymorphism
  • Neo-brutalism
  • Skeuomorphism
  • Flat design
  • Mesh gradient
  • Aurora background
  • Grain texture
  • Glow effect
  • Drop shadow
  • Border radius
  • Grid background
  • Typographic hierarchy
  • Accent color
  • Color contrast

Vibe coding & AI

  • Vibe coding
  • Prompt
  • Context window
  • Token
  • AI agent
  • Tool call
  • Hallucination
  • Diff
  • Live preview
  • Checkpoint
  • Git commit
  • Deploy
  • Frontend and backend
  • API
  • Database
  • Rules file
  • MCP
  • Plan mode
  • Visual edit

Notifications

  • Push notifications

    Comments and mentions

  • Weekly summary

    Every Monday morning

  • Auto-save drafts

    Every 30 seconds