Forms
Switch
<label class="form-check form-switch"><input type="checkbox" role="switch"> Notifications</label>
Colors
Add theme-<color> to the switch (or a whole form).
<label class="form-check form-switch theme-green"><input type="checkbox" role="switch" checked> Notifications</label>
Sizes
<label class="form-check form-switch"><input type="checkbox" role="switch" checked> Default</label>
<label class="form-check form-switch form-switch-lg"><input type="checkbox" role="switch" checked> Large</label>
Text inside
Put a short word in the track — ON / OFF, YES / NO — for switches that must read clearly at a glance: control panels, store settings, kiosks.
- Add
form-switch-textto the label. The track fits its word: the knob, a small gap, the word, the same gap — compact, and the same spacing on every switch. - Write the words on the input:
data-on="ON"shows while it's on (beside the knob, at the start),data-off="OFF"while it's off (at the end). - Longer words (Private, Monthly) just work: moey.js measures the longer of the two words and sizes the track for it, so it doesn't change width when switched. Without JavaScript, short words (ON / OFF, YES / NO) fit.
- Keep the label. The word inside isn't the switch's name — "Wi-Fi" is. Screen readers say "Wi-Fi, switch, on"; the word in the track is hidden from them so nothing is read twice.
<label class="form-check form-switch form-switch-text">
<input type="checkbox" role="switch" data-on="ON" data-off="OFF" checked> Wi-Fi
</label>
<label class="form-check form-switch form-switch-text">
<input type="checkbox" role="switch" data-on="ON" data-off="OFF"> Bluetooth
</label>
<label class="form-check form-switch form-switch-text theme-green">
<input type="checkbox" role="switch" data-on="YES" data-off="NO" checked> Accept orders
</label>
<label class="form-check form-switch form-switch-text">
<input type="checkbox" role="switch" data-on="I" data-off="O"> Power
</label>
Sizes
The word grows with the switch: 10px in the normal one, 12px in form-switch-lg. Its capital letters always sit on the knob's middle line.
<label class="form-check form-switch form-switch-text">
<input type="checkbox" role="switch" data-on="ON" data-off="OFF" checked> Default
</label>
<label class="form-check form-switch form-switch-text form-switch-lg">
<input type="checkbox" role="switch" data-on="ON" data-off="OFF" checked> Large
</label>
Longer words
<label class="form-check form-switch form-switch-text theme-blue">
<input type="checkbox" role="switch" data-on="Public" data-off="Private"> Project visibility
</label>
<label class="form-check form-switch form-switch-text form-switch-lg theme-purple">
<input type="checkbox" role="switch" data-on="Yearly" data-off="Monthly" checked> Billing
</label>
In a settings list
-
Store openCustomers can place orders
<ul class="list-group max-w-md">
<li class="list-group-item">
<div class="list-group-content">
<div class="list-group-title">Store open</div>
<div class="list-group-detail">Customers can place orders</div>
</div>
<label class="form-check form-switch form-switch-text theme-green">
<input type="checkbox" role="switch" data-on="ON" data-off="OFF" checked aria-label="Store open">
</label>
</li>
</ul>
Tips: one short word, in capitals (they are what is centered on the knob) or a single letter; the same pair everywhere in one app; in other languages translate both words — the track adjusts.
| Class / attribute | What it does |
|---|---|
.form-switch-text | A word in the track; the track fits the word |
data-on · data-off (on the input) | The word shown when on · off |
--mo-switch-pad (on the input) | The gap on each side of the word (30% of the height) |
With a description
Wrap the words in a <span> and put a form-text inside it: the description lines up under the label, and clicking it flips the switch too.
<div class="grid grid-cols-1 gap-4 max-w-md">
<label class="form-check form-switch">
<input type="checkbox" role="switch" checked>
<span>Maintenance mode <span class="form-text">Visitors see a "back soon" page.</span></span>
</label>
<label class="form-check form-switch">
<input type="checkbox" role="switch">
<span>Two-step sign-in <span class="form-text">Ask for a code from an app when signing in.</span></span>
</label>
</div>
Disabled and themed
<label class="form-check form-switch"><input type="checkbox" role="switch" checked disabled> Disabled on</label>
<label class="form-check form-switch"><input type="checkbox" role="switch" disabled> Disabled off</label>
<label class="form-check form-switch theme-green"><input type="checkbox" role="switch" checked> Success</label>
<label class="form-check form-switch theme-red"><input type="checkbox" role="switch" checked> Danger</label>
In a settings list
See the list group page for rows with a switch at the end.
- Order emailsWhen a customer places an order
<ul class="list-group max-w-md">
<li class="list-group-item">
<div class="list-group-content">
<div class="list-group-title">Order emails</div>
<div class="list-group-detail">When a customer places an order</div>
</div>
<label class="form-check form-switch">
<input type="checkbox" role="switch" checked aria-label="Order emails">
</label>
</li>
</ul>