Switch

Switches represent standalone boolean settings that apply immediately, including read-only and invalid states.

Overview and decision boundary

Use Switch for settings that turn something on or off immediately.

Do not use Switch when a separate Save, Apply, Submit, or Confirm action is still required unless delayed behavior is clearly communicated.

Notify collaboratorsCollaborators receive updates as they happen.Automatic updatesThis setting is managed by your workspace.
import { Switch } from "@nerio-ui/ui/client";<Switch  defaultChecked  label="Notify collaborators"  description="Collaborators receive updates as they happen."/>

Installation and imports

Install the editable registry source, or use the matching package entrypoint when the product keeps Nerio as a workspace dependency.

pnpm dlx nerio add switchimport { Switch } from "@nerio-ui/ui/client";

Usage

import { Switch } from "@nerio-ui/ui/client";<Switch  defaultChecked  name="notifyCollaborators"  label="Notify collaborators"  description="Collaborators receive updates as they happen."/>

Variants

VariantUse
DefaultStandalone boolean yes/no value.

Anatomy

SlotPurpose
fieldOptional wrapper that groups Switch with its label and description.
rootInteractive Base UI switch control with checked state.
thumbMovable indicator for on and off state.
labelOptional visible name connected to the control with aria-labelledby.
descriptionOptional supporting text connected with aria-describedby.

States

StateBehavior
OffSetting is disabled.
OnSetting is enabled.
DisabledSetting cannot be changed.
Read-onlySetting remains visible without accepting changes.
InvalidValidation state is exposed through aria-invalid and data-invalid.

Motion

  • State changes should use shared motion tokens and preserve reduced-motion behavior.

Accessibility

  • Uses the Base UI Switch primitive for keyboard and checked-state behavior.
  • Use Switch for immediate on/off settings, not multi-select form choices.
  • Provide a visible label or accessible name with aria-label or aria-labelledby; label automatically connects the visible name.
  • Description automatically connects supporting text with aria-describedby, while explicit aria-describedby values are preserved.
  • Supports checked, defaultChecked, onCheckedChange, disabled, required, name, value, form, id, and aria-describedby through the Base UI root props.
  • Invalid, disabled, and read-only states preserve a visible boundary and semantics.
  • Do not use Switch for long-running or destructive actions.

API

PropPurpose
checked / defaultChecked / onCheckedChangeControlled and uncontrolled Base UI state APIs.
labelOptional visible name for the switch field row.
descriptionOptional supporting text displayed below label and announced as a description.
name / value / form / required / disabled / readOnlyNative form metadata is preserved.
invalidSets data-invalid and aria-invalid when true.
classNameExtends the switch control, not the optional field wrapper.

Implementation contract

ContractValue
Registry itemswitch installs 5 Tailwind-first source files into the configured components directory.
Base UIswitch
Registry dependenciesNone.
Package dependencies@base-ui/react, clsx, react, tailwind-merge, tailwindcss

Styling contract

ContractValue
AuthoringComplete, statically detectable Tailwind CSS v4 recipes own component visuals.
ValuesSemantic and component --n-* variables remain the canonical customization layer.
OverridesCustomizable slots merge consumer className values with tailwindCn so conflicting utilities resolve deterministically.
Residual CSSOnly shared keyframes and scoped no-Preflight compatibility rules remain; there is no parallel visual selector layer.

Design notes

  • Use Switch for settings that turn something on or off immediately.

Do / do not

Do

Use for any standalone yes/no value, including preferences, permissions, and form settings.

Do not

Use Switch for selecting several options from a group; use Checkbox for that pattern.

Tokens

GroupTokensControls
Sizing--n-switch-height / --n-switch-widthCompact web track with iOS-like proportions.
Thumb--n-switch-thumb-size / --n-switch-thumb-offsetFixed 2px inset and circular thumb motion.
Off track--n-switch-background / --n-switch-background-hoverNeutral inactive state.
On track--n-switch-background-checked / --n-switch-background-checked-hoverTheme-aware enabled state with an on-primary thumb.
Focus--n-focus-ringVisible keyboard focus treatment.