A pure CSS toggle switch for form input checkboxes
<link rel="stylesheet" href="toggle-switchy.css">
<label for="ID_HERE" class="toggle-switchy">
<input checked type="checkbox" id="ID_HERE">
<span class="toggle">
<span class="switch"></span>
</span>
</label>
Option | Data Attribute |
---|---|
Rounded | data-style="rounded" |
Square | data-style="square" |
No Text | data-text="false" |
Disabled | add the disabled attribute to the input tag |
Checked | add the checked attribute to the input tag |
Sizes | data-size="xl" |
data-size="lg" |
|
medium (default) | |
data-size="sm" |
|
data-size="xs" |
|
Colors | data-color="red" |
data-color="orange" |
|
data-color="yellow" |
|
data-color="green" |
|
data-color="blue" |
|
data-color="purple" |
|
data-color="gray" |
|
Labels | data-label="left" |
label on right (default) | |
input[type='checkbox']
tabindex="0"
to the demo for keyboard accessibility instructionsAuthor: adamculpepper
Demo: https://toggleswitchy.com/
Source Code: https://github.com/adamculpepper/toggle-switchy
#javascript #css