Skip to the content
Konstruktor UI

Actions and inputs

Switch

A native checkbox with role="switch" and .kui-switch. A switch turns a setting on or off at once, with no Save button. Inside a form that is submitted later, use a checkbox.

CSS only

Examples

Settings that act at once

Each switch sits in a label.kui-check row, with the name and an optional hint.

HTML
<div class="kui-choices">
  <label class="kui-check">
    <input class="kui-switch" type="checkbox" role="switch" checked>
    <span class="kui-check__text"><span>Email when a payment arrives</span><span class="kui-hint">To name@example.com</span></span>
  </label>
  <label class="kui-check">
    <input class="kui-switch" type="checkbox" role="switch">
    <span class="kui-check__text"><span>Dark appearance at night</span><span class="kui-hint">From 20:00 to 7:00, by this device’s clock</span></span>
  </label>
  <label class="kui-check">
    <input class="kui-switch" type="checkbox" role="switch" checked>
    <span>Zwei-Faktor-Authentifizierung</span>
  </label>
</div>

Label first, switch at the end

In a settings list the name can come first and the switch at the end of the row. Then the label is the list item itself, so the whole row still toggles the switch.

HTML
<ul class="kui-list">
  <li>
    <label class="kui-list-item">
      <span class="kui-list-item__main"><span class="kui-list-item__title">Sync over mobile data</span><span class="kui-list-item__sub">Photos wait for Wi-Fi either way</span></span>
      <input class="kui-switch" type="checkbox" role="switch">
    </label>
  </li>
  <li>
    <label class="kui-list-item">
      <span class="kui-list-item__main"><span class="kui-list-item__title">Sounds for new messages</span></span>
      <input class="kui-switch" type="checkbox" role="switch" checked>
    </label>
  </li>
</ul>

States

Every state

Off is a grey track; on fills the track with the text colour and moves the knob. Focus shows the ring. Disabled fades the row and cannot be changed. The knob moves without animation when the person asked for reduced motion.

HTML
<div class="kui-choices kui-choices--row">
  <label class="kui-check"><input class="kui-switch" type="checkbox" role="switch"><span>Off</span></label>
  <label class="kui-check"><input class="kui-switch" type="checkbox" role="switch" checked><span>On</span></label>
  <label class="kui-check"><input class="kui-switch" type="checkbox" role="switch" disabled><span>Off, disabled</span></label>
  <label class="kui-check"><input class="kui-switch" type="checkbox" role="switch" checked disabled><span>On, disabled</span></label>
</div>

Classes and attributes

input type="checkbox" role="switch"
The control. role="switch" makes a screen reader say “on” and “off”.
.kui-switch
Draws the track and the knob.
label.kui-check
The row; the whole row toggles the switch.
checked, disabled
On; cannot be changed.

Keyboard

Space
Turns the switch on or off.
Tab
Moves to the next switch.

Accessibility

  • role="switch" on a native checkbox is announced as a switch with its on or off state.
  • The label names the setting, not the state: “Email when a payment arrives”, not “On”.
  • When turning it on takes time or can fail, say so next to it in a status line.
  • The knob has a shadow and the track a filled colour, so on and off differ by more than colour.

Do and do not

Do

  • Use a switch for a setting that applies at once.
  • Keep the label short and the same in both states.
  • Show the result: the setting is applied, or a message says why not.

Do not

  • Do not use a switch in a form with a Submit button; use a checkbox.
  • Do not use a switch for two options that are not on and off; use a segmented control.
  • Do not change the label text when the switch changes.