Single Switch
Standalone toggle for enabling or disabling a single setting
Switch Group
Related settings grouped together with column or row layout
Built-in Features
What you get out of the box with zero configuration
Auto-initializes with the forms system. Two-way binding syncs disabled state between inputs and containers. Use data-state="disabled" on the group to disable all switches at once.
Ripple effect on hover, thumb stretch on press, and smooth slide animation. Three sizes (SM, MD, LG) with proportional scaling.
Space and Enter keys toggle the switch. Track click, label click, and keyboard all fire the switchChange event.
Column layout by default, row layout with nds-rowView class. Gaps adjust on mobile for touch-friendly spacing.
Usage Guidelines
When and how to use switches effectively
When to Use
- Instant on/off actions that take effect immediately without form submission
- Settings pages, preference panels, and feature toggles
- Use checkboxes when the change requires a submit action to apply
- Use radio buttons when choosing between more than two mutually exclusive options
- Always label clearly what state "on" represents
Modifier Classes
| Class | Element | Description |
|---|---|---|
nds-sm | .nds-switch-container | Small size: 36x18px track, 12px thumb |
nds-lg | .nds-switch-container | Large size: 56x28px track, 20px thumb |
nds-neutral | .nds-switch | Uses neutral color palette for the checked state instead of primary |
nds-rowView | .nds-switch-group | Lays out switches in a horizontal row instead of the default column |
Data Attributes
| Attribute | Element | Description |
|---|---|---|
data-state~="disabled" | .nds-switch-container | Disables the individual switch: sets not-allowed cursor and mutes track and thumb colors. Synced automatically from the input's disabled attribute by the forms system |
data-state~="disabled" | .nds-switch-group | Disables all switches in the group at once via CSS opacity and pointer-events |
CSS Custom Properties
| Property | Default | Description |
|---|---|---|
--nds-input-size | 20px | Controls the label line-height and ripple baseline; set via size modifier classes |
--switch-width | 48px | Width of the switch track |
--switch-height | 24px | Height of the switch track |
--switch-thumb-size | 16px | Diameter of the thumb circle |
--switch-thumb-offset | 4px | Distance from the track edge to the thumb in unchecked and checked states |
--switch-track-bg | --background-default | Track background color; overridden by checked state and disabled state |
--switch-track-border | --switch-neutral-default | Track border color; overridden by checked state and disabled state |
--switch-thumb-bg | --switch-neutral-default | Thumb background color; overridden by checked state and disabled state |