v1.3.0 28

Switch

An iOS-style switch control for toggling between on and off states.

Interactive Requires: veritheme.js JS init: automatic

Default

html

Off

On

<div class="vt-text-center">
  <button role="switch" aria-checked="false" class="vt-switch" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
    <span class="vt-switch-thumb"></span>
  </button>
  <p class="vt-caption vt-text-foreground-muted vt-mt-2">Off</p>
</div>
<div class="vt-text-center">
  <button role="switch" aria-checked="true" class="vt-switch vt-active" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
    <span class="vt-switch-thumb"></span>
  </button>
  <p class="vt-caption vt-text-foreground-muted vt-mt-2">On</p>
</div>

Sizes

html

Small

Default

Large

<div class="vt-text-center">
  <button role="switch" aria-checked="true" class="vt-switch vt-switch-sm vt-active" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
    <span class="vt-switch-thumb"></span>
  </button>
  <p class="vt-caption vt-text-foreground-muted vt-mt-2">Small</p>
</div>
<div class="vt-text-center">
  <button role="switch" aria-checked="true" class="vt-switch vt-active" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
    <span class="vt-switch-thumb"></span>
  </button>
  <p class="vt-caption vt-text-foreground-muted vt-mt-2">Default</p>
</div>
<div class="vt-text-center">
  <button role="switch" aria-checked="true" class="vt-switch vt-switch-lg vt-active" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
    <span class="vt-switch-thumb"></span>
  </button>
  <p class="vt-caption vt-text-foreground-muted vt-mt-2">Large</p>
</div>

With Label

html
Airplane Mode
Wi-Fi
Bluetooth
<div class="vt-w-64 vt-space-y-4">
  <div class="vt-flex vt-items-center vt-justify-between">
    <span class="vt-label-md">Airplane Mode</span>
    <button role="switch" aria-checked="false" class="vt-switch" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
      <span class="vt-switch-thumb"></span>
    </button>
  </div>
  <div class="vt-flex vt-items-center vt-justify-between">
    <span class="vt-label-md">Wi-Fi</span>
    <button role="switch" aria-checked="true" class="vt-switch vt-active" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
      <span class="vt-switch-thumb"></span>
    </button>
  </div>
  <div class="vt-flex vt-items-center vt-justify-between">
    <span class="vt-label-md">Bluetooth</span>
    <button role="switch" aria-checked="true" class="vt-switch vt-active" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
      <span class="vt-switch-thumb"></span>
    </button>
  </div>
</div>

Disabled

Switches in disabled state cannot be interacted with.

html

Off (disabled)

On (disabled)

<div class="vt-text-center">
  <button role="switch" aria-checked="false" disabled="" class="vt-switch">
    <span class="vt-switch-thumb"></span>
  </button>
  <p class="vt-caption vt-text-foreground-muted vt-mt-2">Off (disabled)</p>
</div>
<div class="vt-text-center">
  <button role="switch" aria-checked="true" disabled="" class="vt-switch vt-active">
    <span class="vt-switch-thumb"></span>
  </button>
  <p class="vt-caption vt-text-foreground-muted vt-mt-2">On (disabled)</p>
</div>

In Card

Switch rows inside a card container, similar to iOS Settings.

html
Airplane Mode
Wi-Fi
AirPlay
Phone
Notifications
<div class="vt-list vt-max-w-sm">
  <div class="vt-list-item">
    <div class="vt-icon-badge vt-icon-badge-sm vt-icon-badge-square" aria-hidden="true">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" class="vt-icon-badge-icon" aria-hidden="true">
        <path d="M8.87038 6.13264L14.7327 4.19538C18.033 3.10476 19.6831 2.55945 20.5579 3.43426C21.4327 4.30907 20.8874 5.95922 19.7968 9.25953L17.8595 15.1218C16.6236 18.8619 16.0056 20.7319 14.8796 20.9603C14.6411 21.0087 14.3955 21.0129 14.1549 20.9727C13.019 20.7832 12.3132 18.9359 10.9016 15.2413C10.6328 14.5376 10.4983 14.1858 10.2574 13.9127C10.2018 13.8497 10.1424 13.7903 10.0795 13.7348C9.80638 13.4938 9.45455 13.3594 8.75089 13.0906C5.05627 11.679 3.20896 10.9732 3.01945 9.83727C2.97931 9.59669 2.98353 9.35108 3.03189 9.11259C3.26025 7.98657 5.13029 7.36859 8.87038 6.13264Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><path d="M12.8008 11.1865L15.498 8.48926" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path>
      </svg>
    </div>
    <span class="vt-list-item-title">Airplane Mode</span>
    <button role="switch" aria-checked="false" class="vt-switch" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
      <span class="vt-switch-thumb"></span>
    </button>
  </div>
  <div class="vt-list-item">
    <div class="vt-icon-badge vt-icon-badge-sm vt-icon-badge-square" aria-hidden="true">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" class="vt-icon-badge-icon" aria-hidden="true">
        <path d="M8.25 14.5C10.25 12.5 13.75 12.5 15.75 14.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><path d="M18.5 11.5C14.7324 8.16667 9.5 8.16667 5.5 11.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><path d="M2 8.5C8.31579 3.16669 15.6842 3.16668 22 8.49989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><circle cx="12" cy="18" r="1.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></circle>
      </svg>
    </div>
    <span class="vt-list-item-title">Wi-Fi</span>
    <button role="switch" aria-checked="true" class="vt-switch vt-active" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
      <span class="vt-switch-thumb"></span>
    </button>
  </div>
  <div class="vt-list-item">
    <div class="vt-icon-badge vt-icon-badge-sm vt-icon-badge-square" aria-hidden="true">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" class="vt-icon-badge-icon" aria-hidden="true">
        <path d="M15.9922 21H13.9922H9.99219H7.99219" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><path d="M15.9922 3H7.99219C5.16376 3 3.74955 3 2.87087 3.87868C1.99219 4.75736 1.99219 6.17157 1.99219 9V11C1.99219 13.8284 1.99219 15.2426 2.87087 16.1213C3.74955 17 5.16376 17 7.99219 17H15.9922C18.8206 17 20.2348 17 21.1135 16.1213C21.9922 15.2426 21.9922 13.8284 21.9922 11V9C21.9922 6.17157 21.9922 4.75736 21.1135 3.87868C20.2348 3 18.8206 3 15.9922 3Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><path d="M10.4922 21V17M13.4922 17V21" stroke="currentColor" stroke-width="1.5"></path>
      </svg>
    </div>
    <span class="vt-list-item-title">AirPlay</span>
    <button role="switch" aria-checked="false" class="vt-switch" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
      <span class="vt-switch-thumb"></span>
    </button>
  </div>
  <div class="vt-list-item">
    <div class="vt-icon-badge vt-icon-badge-sm vt-icon-badge-square" aria-hidden="true">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" class="vt-icon-badge-icon" aria-hidden="true">
        <path d="M4.90404 10.5413L7.54448 7.90088C8.08309 7.36227 8.26947 6.56642 8.05163 5.83652C7.88129 5.26577 7.68937 4.57964 7.5618 3.99292C7.44381 3.45027 6.96763 3 6.41231 3H4.90404C3.79339 3 2.8813 3.90384 3.00313 5.0078C3.92928 13.3996 10.5926 20.0629 18.9844 20.9891C20.0883 21.1109 20.9922 20.1988 20.9922 19.0881V17.5799C20.9922 17.0246 20.5401 16.569 19.9937 16.4696C19.391 16.36 18.7533 16.1804 18.2198 16.0103C17.4533 15.7659 16.6013 15.9377 16.0325 16.5065L13.4509 19.0881" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path>
      </svg>
    </div>
    <span class="vt-list-item-title">Phone</span>
    <button role="switch" aria-checked="true" class="vt-switch vt-active" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
      <span class="vt-switch-thumb"></span>
    </button>
  </div>
  <div class="vt-list-item">
    <div class="vt-icon-badge vt-icon-badge-sm vt-icon-badge-square" aria-hidden="true">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" class="vt-icon-badge-icon" aria-hidden="true">
        <path d="M16 18C16 20.2091 14.2091 22 12 22C9.79086 22 8 20.2091 8 18" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path><path d="M4.43654 18H19.5625C20.2903 18 20.6542 18 20.8648 17.8951C21.274 17.6913 21.4929 17.2359 21.3964 16.789C21.3468 16.559 21.1194 16.2749 20.6648 15.7066L20.4951 15.4944C20.0392 14.9246 19.8113 14.6397 19.6184 14.3409C19.0187 13.4119 18.6477 12.354 18.5356 11.254C18.4995 10.9002 18.4995 10.5353 18.4995 9.8056V8.5C18.4995 8.03572 18.4995 7.80358 18.4867 7.60758C18.2898 4.60304 15.8965 2.20977 12.892 2.01285C12.696 2 12.4638 2 11.9995 2C11.5353 2 11.3031 2 11.1071 2.01285C8.10258 2.20977 5.70931 4.60304 5.51239 7.60758C5.49954 7.80358 5.49954 8.03572 5.49954 8.5V9.8056C5.49954 10.5353 5.49954 10.9002 5.46349 11.254C5.35143 12.354 4.98035 13.4119 4.38067 14.3409C4.18779 14.6397 3.95985 14.9246 3.50401 15.4944L3.33427 15.7066C2.87964 16.2749 2.65233 16.559 2.60268 16.789C2.50621 17.2359 2.72509 17.6913 3.13431 17.8951C3.3449 18 3.70878 18 4.43654 18Z" stroke="currentColor" stroke-width="1.5"></path>
      </svg>
    </div>
    <span class="vt-list-item-title">Notifications</span>
    <button role="switch" aria-checked="true" class="vt-switch vt-active" onclick="this.classList.toggle('vt-active'); this.setAttribute('aria-checked', this.classList.contains('vt-active'))">
      <span class="vt-switch-thumb"></span>
    </button>
  </div>
</div>

Guidelines

Wi-Fi
Do Pair each switch with a label; the change applies instantly.
Don't Don't show a bare switch — without a label its purpose is unclear.

API Reference

Class Type Description
vt-switch Base Base switch track styles -- rounded pill shape, transition
vt-switch-thumb Base Sliding thumb knob inside the switch track
vt-active State On state — slides the thumb and paints the track brand; toggle only vt-active and aria-checked
vt-switch-sm Size Small switch variant
vt-switch-lg Size Large switch variant
:disabled State The disabled attribute dims the switch and blocks the pointer

Accessibility

Feature Details
Role Use input[type="checkbox"] with role="switch" for toggle semantics
Label Always provide a visible label linked via for/id
Keyboard Space toggles the switch, Tab moves focus
State aria-checked="true/false" announces the toggle state