Skip to content
Dalvan UI

Switch

Use a switch for a binary setting such as email notifications.

Playground

<label class="dv-inline-flex dv-align-items-center dv-gap-100">
  <input type="checkbox" role="switch" class="dv-switch dv-color-primary" />
  Email notifications
</label>

Usage

After setting up the CSS, apply dv-switch to a native checkbox with role="switch" and give it a stable label.

<label>
  <input type="checkbox" role="switch" class="dv-switch" />
  Email notifications
</label>

Examples

Sizes and palette

Medium is the default. The selected palette colors the checked track. Tab to a switch and press Space to toggle it.

<label><input type="checkbox" role="switch" class="dv-switch dv-switch--sm" /> Email</label>
<label><input type="checkbox" role="switch" class="dv-switch dv-color-success" checked /> Updates</label>
<label><input type="checkbox" role="switch" class="dv-switch dv-switch--lg" /> Reminders</label>

Disabled settings

Use disabled when the switch is unavailable. Checked and unchecked states remain visually distinct.

<label><input type="checkbox" role="switch" class="dv-switch" checked disabled /> Managed alerts</label>
<label><input type="checkbox" role="switch" class="dv-switch" disabled /> Optional alerts</label>

API reference

Class or attributeBehavior
dv-switchtype=checkboxrole=switchApplies the switch appearance to a native checkbox and exposes its on/off role.
dv-switch--smdv-switch--mddv-switch--lgSets track dimensions. Medium is the default.
dv-color-*Sets the checked palette. Primary is the default.
checkeddisablednamevalueNative checkbox state and form submission attributes.

Customization

Customize geometry on the input. The thumb size and travel are calculated from the track dimensions and inset.

PropertyEffect and defaults
--dv-switch-width / --dv-switch-heightTrack dimensions set by the selected size.
--dv-switch-insetSpace between track edge and thumb. Defaults to space-25.
--dv-color-focusColor of the keyboard focus outline.