Components/Forms/Switch
COMPONENT09.09

Switch

On/off toggle: a checkbox with role="switch" rendering track and thumb, wired like every other control.


INSTALL

1pnpm dlx @sayagodev/mo add form

Or import the files from the package (no copy):

1import "@sayagodev/mo/css/form.css";

EXAMPLES

Basic
Sizes
With description
Focus is shared across devices, and turns off when you leave the app.
Disabled
Invalid
You must accept the terms and conditions to continue.
Choice cards

USAGE

1<label><input type="checkbox" role="switch" /> Airplane Mode</label>2 3<!-- choice card -->4<label class="flex items-center justify-between gap-4">5  <span class="vstack gap-1">6    <strong>Title</strong>7    <span class="text-light">Description.</span>8  </span>9  <input type="checkbox" role="switch" />10</label>

API

NAMEKINDDESCRIPTION
role="switch"attributeTurns a checkbox into the Switch track/thumb
--mo-switch-width / -thumbtokenTrack and thumb sizing
[data-field] + small.errorclassError reveal on invalid

FILES

src/css/form.css
Install:mo add form

THEMING · PLAYGROUND

This is the exact component from the examples above, wearing a completely different theme. Edit the tokens and --mo-* hooks in the editor — autocomplete knows them all — and the preview obeys in real time. Your CSS always wins.

Tokens & hooks — edit live
Global tokens
--background--border--destructive--foreground--input--muted--muted-foreground--primary--primary-foreground--radius--ring
Component hooks
--mo-field-gap--mo-input-padding-x--mo-input-radius--mo-slider-thumb-bg--mo-switch-thumb--mo-switch-width

Preview

Your CSS

Try it: type --mo- for the component hooks, or edit any value — the preview obeys in real time.