Switch - National Design System

Toggle switches for binary choices with clear visual feedback and accessibility support

Single Switch

Standalone toggle for enabling or disabling a single setting

Switch Group

Related settings grouped together with column or row layout

Notification preferences

Built-in Features

What you get out of the box with zero configuration

Form Integration

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.

Visual Feedback

Ripple effect on hover, thumb stretch on press, and smooth slide animation. Three sizes (SM, MD, LG) with proportional scaling.

Keyboard Support

Space and Enter keys toggle the switch. Track click, label click, and keyboard all fire the switchChange event.

Responsive Layout

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

JavaScript API

// Listen for switch state changes var switchEl = document.querySelector('.nds-switch'); switchEl.addEventListener('switchChange', function(e) { console.log('Checked:', e.detail.checked); console.log('Value:', e.detail.value); console.log('Input:', e.detail.input); }); // Toggle programmatically var input = document.querySelector('.nds-switch-input'); input.checked = !input.checked; input.dispatchEvent(new Event('change'));
Was this page useful?
60% of users said Yes from 2843 Feedbacks