Switch
Allow users to toggle between a binary option.
Allow users to toggle between a binary option.
npm install @vrembem/switch@use "@vrembem/switch";Switch uses design token CSS variables in a reference and fallback pattern. Variables are referenced in the component's styles but are not directly defined; instead, they are provided with sensible fallbacks.
| Variable | Fallback |
|---|---|
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
There are no variables that match your search.
Switch form controls are composed using the <input type="checkbox"> element along with the .switch class.
<input class="switch" type="checkbox" />For switch with labels, just wrap the switch element along with label text using the <label> element.
<label>
<input class="switch" type="checkbox" />
<span>Switch with a label</span>
</label>Adding the boolean disabled attribute to the input element will provide visual indication that the switch is not available for use.
<input class="switch" type="checkbox" disabled />Adding the is-invalid class or aria-invalid="true" attribute to the switch component will provide visual indication that the form-control value is invalid. Invalid state is also triggered by the native :user-invalid state.
<input class="switch is-invalid" type="checkbox" />