Toggle
A specialized form input component that provides a toggle switch interface with customizable on/off states, labels, and styles.Basic Toggle
Creates a standard toggle with default settings.
Options
The Toggle component supports various configuration options.onLabel
: Text for the on state label (default: "On")offLabel
: Text for the off state label (default: "Off")onStyle
: Bootstrap style for the on state (default: "primary")offStyle
: Bootstrap style for the off state (default: "secondary")onValue
: Value when toggle is on (optional)offValue
: Value when toggle is off (optional)size
: Size of the toggle (from ToggleSizeEnum)style
: Custom CSS class to appendwidth
: Custom width in pixelsheight
: Custom height in pixelstabindex
: Tab index for keyboard navigationtristate
: Whether to support indeterminate statechecked
: Whether the toggle is checked (inherited from Checkbox)value
: The value of the toggle (inherited from Checkbox)
Toggle Examples
Here are examples of different ways to use the toggle component.Labeled Toggle
Creates a toggle with custom on/off labels.
Styled Toggle
Creates a toggle with specific Bootstrap styles for on/off states.
Sized Toggle
Creates a toggle with a specific size.
Full-featured Toggle
Creates a toggle with all available customizations.
API
The toggle component extends from theCheckbox
class so it has all its methods available.Common alternative names: Toggle Switch, Binary Switch, On/Off Switch, Toggle Button, Flip Switch, Slider Switch, Binary Toggle
Types: Basic Toggle, Labeled Toggle, Styled Toggle, Sized Toggle, Tristate Toggle, Value Toggle
Principles
Visual Feedback
Toggle switches provide immediate visual feedback through their sliding animation and color changes, making the current state clear to users.
Binary Clarity
The component's design emphasizes the binary nature of the choice, making it clear that there are only two possible states (or three with tristate).
Consistency
Maintains consistent styling and behavior while providing customization options for different use cases.
Anatomy

- Container
- Input
- Toggle
- Labels
- Track
- Thumb
Outer wrapper with toggle classes
Hidden checkbox input element
Visual sliding element
On/off state text indicators
Background element that the toggle slides along
The moving part of the toggle
Usage
Use toggles for:
- Feature toggles
- Settings options
- Binary choices
- On/off states
- Enable/disable controls
- Mode switches
- Preference settings
Best Practices
- Use clear, concise labels that describe the action
- Choose appropriate styles for on/off states
- Consider the context when choosing between a toggle and other input types
- Use consistent styling across related toggles
- Ensure the toggle is large enough to be easily clickable
- Consider using tristate for options that can be partially enabled
- Provide meaningful values for on/off states when needed
Common Patterns
Settings Panels
- User preferences
- Feature flags
- Notification settings
- Privacy controls
- Display options
Form Controls
- Required field indicators
- Form validation toggles
- Auto-save controls
- Advanced options
- Batch operations
Interface Controls
- Dark/light mode
- Layout options
- View preferences
- Filter toggles
- Sort options
Accessibility
- Ensure proper ARIA attributes are set
- Maintain keyboard navigation support
- Provide clear focus states
- Use appropriate color contrast
- Include descriptive labels
- Consider screen reader announcements
- Test with various assistive technologies