Malevich

Elements / Interactive/

Switch

On/off toggle on native checkbox. Track + thumb in CSS.

Switch

An on/off toggle. Built on native <input type="checkbox">. The native input is visually hidden (but accessible) while a CSS-drawn track and thumb provide the switch appearance. CSS-only.

When to use

Use a switch when a setting takes immediate effect — turning on notifications, enabling dark mode, etc. The change applies as the switch flips, with no "Save" step.

If the setting needs explicit confirmation, use a Checkbox with a form action.

Variants

Variant Class Use for
Default .switch Standard accent fill when on
Success .switch.-success Positive-state toggle (active / safe)
Danger .switch.-danger Risky state (mute / unsafe enable)
Small .switch.-s Compact size for dense UIs

Anatomy

<label class="switch">
  <input type="checkbox" class="switch__input" />
  <span class="switch__track"></span>
  <span class="switch__label">Enable notifications</span>
</label>

<!-- Pre-checked -->
<label class="switch -success">
  <input type="checkbox" class="switch__input" checked />
  <span class="switch__track"></span>
  <span class="switch__label">Auto-save</span>
</label>

<!-- Disabled -->
<label class="switch">
  <input type="checkbox" class="switch__input" disabled />
  <span class="switch__track"></span>
  <span class="switch__label">Coming soon</span>
</label>

The <label> wraps everything so the entire switch is clickable; the <input> is visually hidden but accepts focus and keyboard input.

Tokens used

From semantic tier

Component-tier (defined inline)

Accessibility

The native <input type="checkbox"> carries all required semantics:

The component uses the standard "visually hidden" pattern for the input. This is the recommended approach over appearance: none + custom styling because it preserves every accessibility behavior of the native control.

Edge cases

Do

Don't