Skip to main content
The Switch component provides a toggle control for turning options on or off with a sliding animation.

Basic usage

<flx-switch
  label="Enable notifications"
  [(ngModel)]="notificationsEnabled">
</flx-switch>

Properties

label
string
Label text displayed next to the switch
checked
boolean
default:"false"
Whether the switch is on
disabled
boolean
default:"false"
Disables the switch
labelPosition
'before' | 'after'
default:"after"
Position of the label relative to the switch
size
'small' | 'medium' | 'large'
default:"medium"
Size of the switch
color
string
Custom color for the active state

Events

checkedChange
EventEmitter<boolean>
Emitted when the switch state changes

Examples

<flx-switch
  label="Dark mode"
  [(ngModel)]="darkMode">
</flx-switch>

<flx-switch
  label="Auto-save"
  [(ngModel)]="autoSave">
</flx-switch>

<flx-switch
  label="Email notifications"
  [(ngModel)]="emailNotifications">
</flx-switch>
export class Settings {
  darkMode = false;
  autoSave = true;
  emailNotifications = true;
}

Styling

flx-switch {
  --flx-switch-width: 44px;
  --flx-switch-height: 24px;
  --flx-switch-track-background: #d1d5db;
  --flx-switch-track-checked-background: #3b82f6;
  --flx-switch-handle-size: 20px;
  --flx-switch-handle-background: #ffffff;
  --flx-switch-border-radius: 12px;
  --flx-switch-disabled-opacity: 0.5;
  --flx-switch-transition-duration: 200ms;
}

Accessibility

The Switch component provides full accessibility:
  • role="switch" with aria-checked state
  • Space key toggles the switch
  • Focus indicators
  • Proper label association
  • Disabled state handling

Switch vs Checkbox

Use Switch for settings that take immediate effect (like toggling dark mode). Use Checkbox for form selections that require submission (like accepting terms).
Use Switch whenUse Checkbox when
Effect is immediatePart of a form submission
Binary on/off stateMultiple selections allowed
System/app settingsAgreement/consent
Real-time togglesData collection

Best practices

  • Use clear, action-oriented labels (“Enable notifications” not “Notifications”)
  • Provide immediate visual feedback when state changes
  • Show a loading state for switches that trigger async operations
  • Group related switches together
  • Consider adding descriptions for complex settings
  • Use consistent switch placement in settings lists
  • Checkbox - For multiple selections or form submissions
  • Segmented Button - For multiple mutually exclusive options
  • Radio - For single selection from multiple options

Build docs developers (and LLMs) love