Skip to content

Switch ​

Toggle switch with labels, icons, loading, async confirmation, and custom values.

false
vue
<script setup lang="ts">
const value = ref(false)
</script>

<template>
  <VxSwitch v-model="value" />
</template>

With Label ​

vue
<template>
  <VxSwitch v-model="value" label="Enable notifications" />
  <VxSwitch v-model="value" label="Dark mode" description="Switch between themes" />
</template>

Active / Inactive Text ​

vue
<template>
  <VxSwitch active-text="On" inactive-text="Off" />
</template>

Inline Text ​

Text inside the track.

vue
<template>
  <VxSwitch active-text="ON" inactive-text="OFF" inline-text />
</template>

Icons ​

vue
<template>
  <VxSwitch v-model="value">
    {{ value ? '🌙 Dark' : '☀️ Light' }}
  </VxSwitch>
</template>

Custom Colors ​

vue
<template>
  <VxSwitch active-color="#22c55e" />
  <VxSwitch active-color="#ef4444" inactive-color="#374151" />
</template>

Custom Values ​

Use non-boolean values.

v-model: "dark"
v-model: 1 (number)
vue
<template>
  <VxSwitch v-model="theme" active-value="dark" inactive-value="light" />
  <!-- v-model: "dark" or "light" -->

  <VxSwitch v-model="status" :active-value="1" :inactive-value="0" />
  <!-- v-model: 1 or 0 -->
</template>

Sizes ​

xssmdefaultlgxl
vue
<template>
  <VxSwitch size="xs" />
  <VxSwitch size="sm" />
  <VxSwitch />
  <VxSwitch size="lg" />
  <VxSwitch size="xl" />
</template>

Square ​

vue
<template>
  <VxSwitch square />
</template>

Loading ​

vue
<template>
  <VxSwitch v-model="value" loading />
</template>

Before Change (Async) ​

Ask for confirmation before toggling.

true
vue
<script setup>
async function beforeChange() {
  return confirm('Are you sure?')
}
</script>

<template>
  <VxSwitch v-model="value" :before-change="beforeChange" />
</template>

Readonly ​

vue
<template>
  <VxSwitch :model-value="true" readonly />
</template>

Disabled ​

vue
<template>
  <VxSwitch disabled />
</template>

Reverse Layout ​

Place the switch on the right side of the label.

vue
<template>
  <VxSwitch v-model="value" label="Wi-Fi" description="..." reverse />
</template>

Press Animation ​

The thumb stretches when pressed, providing tactile feedback. Try pressing and holding any switch above to see the effect.

Props ​

PropTypeDefaultDescription
modelValueboolean | string | numberfalseValue (v-model)
activeValueboolean | string | numbertrueValue when on
inactiveValueboolean | string | numberfalseValue when off
disabledbooleanfalseDisable
loadingbooleanfalseLoading spinner
readonlybooleanfalseRead only
size'xs' | 'sm' | 'default' | 'lg' | 'xl''default'Size
activeColorstring''On color
inactiveColorstring''Off color
activeTextstring''Text when on
inactiveTextstring''Text when off
activeIconComponent—Icon when on (inside thumb)
inactiveIconComponent—Icon when off (inside thumb)
inlineTextbooleanfalseShow text inside track
labelstring''Label text
descriptionstring''Description below label
squarebooleanfalseSquare shape
beforeChange() => boolean | Promise<boolean>—Async guard before toggle
requiredbooleanfalseMark as required for form validation
reversebooleanfalsePlace switch on the right side
trackClassstring | string[] | object—Custom class(es) for the track
thumbClassstring | string[] | object—Custom class(es) for the thumb

Events ​

EventTypeDescription
update:modelValue(v)Value changed
change(v)Value changed

Slots ​

SlotDescription
defaultCustom label content
descriptionCustom description