Import
Usage
Props
HTML id for the checkbox input and label association.
When true, displays as a checkbox-style toggle where the indicator appears/disappears. When false (default), displays as a sliding toggle.
When true, uses fully rounded corners (
rounded-full). When false (default), uses the theme’s standard border radius.Custom CSS class string (note: this uses a regular string, not an object like other components).
All standard HTML checkbox input attributes are supported (except
type, bind:checked, and standard class).Examples
Behavior
The component uses the native checkbox input with custom styling. The actual checkbox is visually hidden with
sr-only but remains accessible to screen readers. The visual indicator animates smoothly with transitions.Visual Variants
Sliding Toggle (default):- Width:
3rem(12) - Indicator slides from left to right when checked
- Uses
translate-x-fulltransform
- Width:
1.75rem(7) - Indicator fades in/out using opacity
- Indicator is centered, not sliding
- Applies
rounded-fullto both container and indicator - Works with both sliding and checkbox styles
Styling
- Height:
1.75rem(7) for consistent sizing - Indicator:
1.25rem(5) square with borders - Smooth transitions (300ms default, 75ms on hover)
- Background changes color when checked (accent color)
- Uses peer selectors for checkbox state styling
touch-manipulationprevents double-tap zoom
Accessibility
- Native checkbox input for proper semantics
- Screen reader accessible with
sr-onlyclass - Label associated via
forattribute - Keyboard accessible (Space to toggle)
- Focus state indicated via
peer-focusstyles select-noneon label prevents text selection- Label hidden when empty with
empty:hidden