Keyboard shortcut: Ctrl + K
Get started

Switch

Use VSwitch for an on/off setting applied immediately. It exposes role="switch" to assistive technology.

Usage

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vectis-ui'

const notifications = ref(true)
</script>

<template>
  <VSwitch v-model="notifications">Notifications</VSwitch>
</template>

Examples

Hint

Use label or the default slot for the name. hint adds help text linked through aria-describedby.

vue

Joins known networks automatically.

Visible to nearby devices while on.

<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vectis-ui'

const wifi = ref(true)
const bluetooth = ref(false)
</script>

<template>
  <div class="stack">
    <VSwitch v-model="wifi" label="Wi-Fi" hint="Joins known networks automatically." />
    <VSwitch v-model="bluetooth" label="Bluetooth" hint="Visible to nearby devices while on." />
  </div>
</template>

<style scoped>
.stack {
  display: grid;
  justify-items: start;
  gap: var(--vectis-space-3);
}
</style>

Label position

labelPosition="start" places the label before the switch.

vue
<script setup lang="ts">
import { VSwitch } from 'vectis-ui'
</script>

<template>
  <div class="stack">
    <VSwitch>Label after the switch, the default</VSwitch>
    <VSwitch label-position="start">Label before the switch</VSwitch>
  </div>
</template>

<style scoped>
/* Keep the clickable label from stretching across the grid. */
.stack {
  display: grid;
  justify-items: start;
  gap: var(--vectis-space-3);
}
</style>

Full width

spread fills the available width and places the label and switch at opposite ends.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vectis-ui'

const digest = ref(true)
const twoFactor = ref(false)
</script>

<template>
  <div class="settings">
    <VSwitch v-model="digest" spread>Weekly digest</VSwitch>
    <VSwitch v-model="twoFactor" spread label-position="start">Two-factor authentication</VSwitch>
  </div>
</template>

<style scoped>
.settings {
  display: grid;
  gap: var(--vectis-space-3);
  inline-size: 100%;
  max-inline-size: 24rem;
  padding: var(--vectis-space-4);
  border: 1px solid var(--vectis-color-border);
  border-radius: var(--vectis-radius-surface);
}
</style>

Read-only

readonly prevents changes by click or Space while preserving focus and native form behavior. It sets aria-readonly.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vectis-ui'

const on = ref(true)
const off = ref(false)
</script>

<template>
  <div class="stack">
    <VSwitch v-model="on" readonly label="Managed by your administrator" />
    <VSwitch v-model="off" readonly label="Locked until the next billing period" />
  </div>
</template>

<style scoped>
.stack {
  display: grid;
  justify-items: start;
  gap: var(--vectis-space-3);
}
</style>

Disabled

disabled prevents changes and removes the switch from Tab navigation and form submission.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VSwitch } from 'vectis-ui'

const off = ref(false)
const on = ref(true)
</script>

<template>
  <div class="stack">
    <VSwitch v-model="off" disabled>Off, and cannot be turned on</VSwitch>
    <VSwitch v-model="on" disabled>On, and cannot be turned off</VSwitch>
  </div>
</template>

<style scoped>
.stack {
  display: grid;
  justify-items: start;
  gap: var(--vectis-space-3);
}
</style>

API

Props

PropTypeDefault
labelstringnone
Visible label, replaced by the default slot. Without either, provide aria-label or aria-labelledby.
hintstringnone
Help text below the label, linked through aria-describedby.
errorstringnone
Error message shown in place of the hint. Sets aria-invalid, is linked through aria-describedby and is announced when it appears.
labelPositionSwitchLabelPosition'start' | 'end''end'
Label before the switch with start, or after it with end.
spreadbooleanfalse
Fills the available width and separates the label and switch.
invalidbooleanfalse
Sets aria-invalid and the error style. Does not block form submission by itself.
disabledbooleanfalse
Disables the switch and excludes it from focus and form submission.
readonlybooleanfalse
Prevents changes while keeping the switch focusable. Sets aria-readonly; native form submission and validation still apply.
v-modelbooleanfalse
On/off state, a boolean defaulting to false. Use native name and value attributes for form submission.

Slots

SlotType
default{}
Clickable label content, replacing label.

CSS variables

TokenValue
--vectis-control-size-switch-w2.25rem
--vectis-control-size-switch-h1.25rem
--vectis-control-size-switch-pad0.125rem