Basic Usage

Simple on/off switch with state binding

Live Demo
Toggle me:
State: OFF
Code
 
Explanation

Two-way Binding

Use bind:checked to create a two-way binding between the switch and your component state.

Reactive State

The switch automatically updates when the bound variable changes, and vice versa.

Size Customization

Control the size of your switches

Live Demo
Small (30px):
Default (50px):
Large (80px):
Code
 
Size Guidelines

Size Property

The size prop controls the height (and width for square switches) in pixels.

Responsive Design

Consider using CSS media queries or responsive size values for different screen sizes.

Disabled State

Prevent user interaction when needed

Live Demo
Disabled (OFF):
State: OFF
Disabled (ON):
State: ON
Code
 
Use Cases

When to Disable

  • During async operations
  • When permissions are insufficient
  • For read-only configuration display
  • When dependencies aren't met

Accessibility

Disabled switches are properly marked with ARIA attributes for screen readers.

Orientation

Horizontal or vertical layout options

Live Demo
Horizontal (default)
Vertical
State: OFF
Code
 
Design Guidelines

Layout Considerations

Vertical switches work well in compact layouts or when you need to save horizontal space.

Size Recommendations

Consider using larger sizes for vertical switches to maintain good usability and visual balance.

Event Handling

Respond to switch state changes

Live Demo
Toggle me:
State: OFF
Code
 
Event Details

onToggle Callback

The onToggle prop accepts a function that receives the new state value.

Common Use Cases

  • Logging state changes
  • Triggering API calls
  • Updating other UI elements
  • Form validation

Next Steps

🎛️
Multi Switch

Learn about multi-state switches

Multi Examples
🎨
Styling

Customize colors and appearance

Styling Guide
Advanced

Advanced features and techniques

Advanced Examples