Swap
Flips between two elements when its hidden checkbox is toggled. No JavaScript.
| Name | Type | What it does |
|---|---|---|
swap | component | A <label> wrapping a checkbox and the two states |
swap-on | part | Shown while the checkbox is checked |
swap-off | part | Shown while it is not |
Icon swap
<label class="swap btn btn-circle" aria-label="Toggle theme">
<input type="checkbox">
<span class="swap-on"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 14.500A8 8 0 0 1 9.500 4a8 8 0 1 0 10.500 10.500z"/></svg></span>
<span class="swap-off"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M4.900 4.900l1.400 1.400m11.400 11.400 1.400 1.400M2 12h2m16 0h2M4.900 19.100l1.400-1.400M17.700 6.300l1.400-1.400"/></svg></span>
</label>Text swap
<label class="swap">
<input type="checkbox">
<span class="swap-on badge badge-success">Online</span>
<span class="swap-off badge">Offline</span>
</label>