Toggle
Tailwind CSS and Alpine JS Toggle
A switch control that allows you to toggle between two states, such as on or off.
Default Toggle
A toggle switch that uses a checkbox input to determine its state (true or false).
HTML
<label for="defaultToggle" class="">
<input id="defaultToggle" type="checkbox" class="" disabled role="switch" checked />
<span class="">Toggle</span>
<div class="" aria-hidden="true"></div>
<span class="">Toggle</span>
</label>
Toggle with Container
A toggle switch with a contrasting background and label that makes it easy to find and interact with it.
HTML
<label for="toggleWithContainer" class="">
<input id="toggleWithContainer" type="checkbox" class="" disabled role="switch" checked />
<span class="">Toggle</span>
<div class="" aria-hidden="true"></div>
<span class="">Toggle</span>
</label>
Toggle Color Variations
Examples of toggle switches with different color variations.
HTML
<!-- Toggle Primary -->
<label for="togglePrimary" class="">
<input id="togglePrimary" type="checkbox" class="" disabled role="switch" checked />
<span class="">primary</span>
<div class="" aria-hidden="true"></div>
<span class="">primary</span>
</label>
<!-- Toggle Secondary -->
<label for="toggleSecondary" class="">
<input id="toggleSecondary" type="checkbox" class="" disabled role="switch" checked />
<span class="">secondary</span>
<div class="" aria-hidden="true"></div>
<span class="">secondary</span>
</label>
<!-- Toggle Success -->
<label for="toggleSuccess" class="">
<input id="toggleSuccess" type="checkbox" class="" disabled role="switch" checked />
<span class="">success</span>
<div class="" aria-hidden="true"></div>
<span class="">success</span>
</label>
<!-- Toggle Warning -->
<label for="toggleWarning" class="">
<input id="toggleWarning" type="checkbox" class="" disabled role="switch" checked />
<span class="">warning</span>
<div class="" aria-hidden="true"></div>
<span class="">warning</span>
</label>
<!-- Toggle Danger -->
<label for="toggleDanger" class="">
<input id="toggleDanger" type="checkbox" class="" disabled role="switch" checked />
<span class="">danger</span>
<div class="" aria-hidden="true"></div>
<span class="">danger</span>
</label>
<!-- Toggle Info -->
<label for="toggleInfo" class="">
<input id="toggleInfo" type="checkbox" class="" disabled role="switch" checked />
<span class="">info</span>
<div class="" aria-hidden="true"></div>
<span class="">info</span>
</label>
Keyboard Navigation
Key | Action |
---|---|
Tab |
Toggle gets the focus |
Space |
Toggles on and off |