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 attribute | Behavior |
|---|---|
dv-switchtype=checkboxrole=switch | Applies the switch appearance to a native checkbox and exposes its on/off role. |
dv-switch--smdv-switch--mddv-switch--lg | Sets track dimensions. Medium is the default. |
dv-color-* | Sets the checked palette. Primary is the default. |
checkeddisablednamevalue | Native 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.
| Property | Effect and defaults |
|---|---|
--dv-switch-width / --dv-switch-height | Track dimensions set by the selected size. |
--dv-switch-inset | Space between track edge and thumb. Defaults to space-25. |
--dv-color-focus | Color of the keyboard focus outline. |