Keyboard shortcut: Ctrl + K
Get started

Slider

VSlider selects a number or a range with one or two thumbs. Optional number fields allow precise entry.

Usage

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

const volume = ref(40)
</script>

<template>
  <div class="demo">
    <VSlider v-model="volume" label="Volume" />
  </div>
</template>

<style scoped>
.demo {
  inline-size: 20rem;
}
</style>

Examples

Range

range uses an ordered pair. Moving one thumb past the other pushes both to the new value.

vue
Budget

20 to 60

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

const budget = ref<[number, number]>([20, 60])
</script>

<template>
  <div class="demo">
    <VSlider v-model="budget" range label="Budget" />
    <p class="value">{{ budget[0] }} to {{ budget[1] }}</p>
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-3);
  inline-size: 20rem;
}
.value {
  margin: 0;
  color: var(--vectis-color-text-muted);
  font-size: var(--vectis-text-caption-size);
}
</style>

Min and max

min and max set the bounds, including negative values.

vue

Temperature, -10 to 40

Temperature

19 °C

Rating, 1 to 5

Rating

3 out of 5

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

const temperature = ref(19)
const rating = ref(3)
</script>

<template>
  <div class="demo">
    <div class="row">
      <p class="caption">Temperature, -10 to 40</p>
      <VSlider v-model="temperature" :min="-10" :max="40" label="Temperature" />
      <p class="value">{{ temperature }} °C</p>
    </div>

    <div class="row">
      <p class="caption">Rating, 1 to 5</p>
      <VSlider v-model="rating" :min="1" :max="5" ticks label="Rating" />
      <p class="value">{{ rating }} out of 5</p>
    </div>
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-6);
  inline-size: 20rem;
}
.row {
  display: grid;
  gap: var(--vectis-space-2);
}
.caption,
.value {
  margin: 0;
  color: var(--vectis-color-text-muted);
  font-size: var(--vectis-text-caption-size);
}
</style>

Steps

step sets the increment. ticks marks stops when there are at most 50 steps.

vue

step 10, with ticks

Quantity

step 0.1

Opacity

0.4

0 to 95 by 10, so the last stop is 90

Coverage

50

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

const quantity = ref(50)
const opacity = ref(0.4)
const odd = ref(50)
</script>

<template>
  <div class="demo">
    <div class="row">
      <p class="caption">step 10, with ticks</p>
      <VSlider v-model="quantity" :step="10" ticks label="Quantity" />
    </div>

    <div class="row">
      <p class="caption">step 0.1</p>
      <VSlider v-model="opacity" :min="0" :max="1" :step="0.1" ticks label="Opacity" />
      <p class="value">{{ opacity }}</p>
    </div>

    <!-- This step ends at 90, below max 95. More than fifty steps hides the ticks. -->
    <div class="row">
      <p class="caption">0 to 95 by 10, so the last stop is 90</p>
      <VSlider v-model="odd" :max="95" :step="10" ticks label="Coverage" />
      <p class="value">{{ odd }}</p>
    </div>
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-6);
  inline-size: 20rem;
}
.row {
  display: grid;
  gap: var(--vectis-space-2);
}
.caption,
.value {
  margin: 0;
  color: var(--vectis-color-text-muted);
  font-size: var(--vectis-text-caption-size);
}
</style>

Text labels

labels names each step and supplies its accessible value text. It also enables ticks.

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

const size = ref(2)
</script>

<template>
  <div class="demo">
    <VSlider v-model="size" :min="0" :max="4" :labels="['XS', 'S', 'M', 'L', 'XL']" label="Size" />
  </div>
</template>

<style scoped>
.demo {
  inline-size: 20rem;
  padding-inline: var(--vectis-space-4);
}
</style>

Icon labels

Labels can mix strings and objects containing an icon and accessible text.

vue
Alert threshold

Information

<script setup lang="ts">
import { ref } from 'vue'
import { VSlider, type SliderLabel } from 'vectis-ui'
import { check_circle as checkCircle, error, info, warning } from 'vectis-ui/icons'

const threshold = ref(1)

const labels = [
  { icon: checkCircle, label: 'Silent' },
  { icon: info, label: 'Information' },
  { icon: warning, label: 'Warning' },
  { icon: error, label: 'Error' },
] satisfies SliderLabel[]
</script>

<template>
  <div class="demo">
    <VSlider v-model="threshold" :min="0" :max="3" :labels="labels" label="Alert threshold" />
    <p class="value">{{ labels[threshold]?.label }}</p>
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-3);
  inline-size: 20rem;
  padding-inline: var(--vectis-space-4);
}
.value {
  margin: 0;
  color: var(--vectis-color-text-muted);
  font-size: var(--vectis-text-caption-size);
}
</style>

Value tooltip

tooltip displays the value during dragging or keyboard focus.

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

const volume = ref(40)
const budget = ref<[number, number]>([20, 60])
</script>

<template>
  <div class="demo">
    <VSlider v-model="volume" tooltip label="Volume" />

    <VSlider v-model="budget" tooltip range label="Budget" />
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-8);
  inline-size: 20rem;
  padding-block-start: var(--vectis-space-6);
}
</style>

Number fields

inputs adds VNumberInput fields. Blur or Enter commits the value, bounded and snapped to the step. Invalid entries restore the previous value.

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

const volume = ref(40)
const budget = ref<[number, number]>([20, 60])
</script>

<template>
  <div class="demo">
    <!-- Commit on blur or Enter to avoid clamping partially typed numbers. -->
    <VSlider v-model="volume" inputs="ends" label="Volume" />
    <VSlider v-model="budget" inputs="ends" range label="Budget" />
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-6);
  inline-size: 26rem;
}
</style>

Field placement

ends places fields beside the track; top and bottom place them above or below. On vertical sliders, these become the start and end sides.

vue
Budget
Volume
Gain
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'

const budget = ref<[number, number]>([20, 60])
const volume = ref(40)
const gain = ref<[number, number]>([30, 70])
</script>

<template>
  <div class="demo">
    <VSlider v-model="budget" inputs="top" range label="Budget" />
    <VSlider v-model="volume" inputs="bottom" label="Volume" />

    <VSlider v-model="gain" orientation="vertical" inputs="top" range label="Gain" />
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-6);
  inline-size: 26rem;
}
</style>

Number format

formatOptions takes Intl.NumberFormat options and locale a language tag. Both apply to the tooltip, the number fields and the value thumbs announce. min, max and step stay in model units: with style: "percent", 0.25 shows as 25%.

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

const price = ref<[number, number]>([120, 300])
const discount = ref(0.25)

const euros = { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 } as const
const percent = { style: 'percent' } as const
</script>

<template>
  <div class="demo">
    <VSlider
      v-model="price"
      range
      :max="500"
      :step="10"
      inputs="ends"
      tooltip
      label="Price"
      :format-options="euros"
    />
    <VSlider
      v-model="discount"
      :max="1"
      :step="0.05"
      tooltip
      label="Discount"
      :format-options="percent"
    />
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-6);
  inline-size: 26rem;
  padding-block-start: var(--vectis-space-6);
}
</style>

Field sizes

size adjusts number fields. A size set by VInputGroup takes precedence.

vue
Small
Medium
Large
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'

const small = ref(20)
const medium = ref(40)
const large = ref(60)
</script>

<template>
  <div class="demo">
    <VSlider v-model="small" inputs="ends" size="sm" label="Small" />
    <VSlider v-model="medium" inputs="ends" label="Medium" />
    <VSlider v-model="large" inputs="ends" size="lg" label="Large" />
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-6);
  inline-size: 26rem;
}
</style>

Orientation

orientation="vertical" places the lowest value at the bottom.

vue
Volume
Budget
Gain
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'

const volume = ref(40)
const budget = ref<[number, number]>([20, 60])
const gain = ref(60)
</script>

<template>
  <div class="demo">
    <VSlider v-model="volume" orientation="vertical" label="Volume" />
    <VSlider v-model="budget" orientation="vertical" range tooltip label="Budget" />

    <VSlider v-model="gain" class="tall" orientation="vertical" inputs="ends" label="Gain" />
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  align-items: start;
  gap: var(--vectis-space-8);
}
.tall {
  --vectis-control-size-slider-length: 16rem;
}
</style>

Disabled

disabled disables thumbs and number fields.

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

const volume = ref(30)
const budget = ref<[number, number]>([20, 60])
</script>

<template>
  <div class="demo">
    <VSlider v-model="volume" disabled label="Volume" />
    <VSlider v-model="budget" range :step="10" ticks inputs="ends" disabled label="Budget" />
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-6);
  inline-size: 26rem;
}
</style>

Read-only

readonly prevents pointer and keyboard changes while preserving focus.

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

const volume = ref(40)
const budget = ref<[number, number]>([20, 60])
</script>

<template>
  <div class="demo">
    <VSlider v-model="volume" readonly label="Volume" />
    <VSlider v-model="budget" range inputs="ends" readonly label="Budget" />
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-6);
  inline-size: 26rem;
}
</style>

Invalid

invalid marks thumbs and number fields with aria-invalid and the error style.

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

const quota = ref<[number, number]>([30, 90])
</script>

<template>
  <div class="demo">
    <VSlider v-model="quota" range inputs="ends" invalid label="Quota" />
  </div>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-6);
  inline-size: 26rem;
}
</style>

In a form

label is shown above the slider and names its thumbs; hideLabel hides it visually. Consumer ARIA names take precedence. Native attributes reach the end thumb; in range mode, only that value is submitted.

vue
Volume

Nothing submitted yet

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

const volume = ref(40)
const submitted = ref<string | null>(null)

function onSubmit(event: Event) {
  const data = new FormData(event.target as HTMLFormElement)
  submitted.value = [...data].map(([key, value]) => `${key}=${value}`).join(', ')
}
</script>

<template>
  <form class="demo" @submit.prevent="onSubmit">
    <VSlider v-model="volume" name="volume" label="Volume" />

    <VButton class="submit" type="submit" size="sm" variant="outline" tone="neutral">
      Submit
    </VButton>
    <p class="log">{{ submitted ?? 'Nothing submitted yet' }}</p>
  </form>
</template>

<style scoped>
.demo {
  display: grid;
  gap: var(--vectis-space-3);
  inline-size: 20rem;
}
.submit {
  justify-self: start;
}
.log {
  margin: 0;
  color: var(--vectis-color-text-muted);
  font-size: var(--vectis-text-caption-size);
}
</style>

API

Props

PropTypeDefault
minnumber0
Minimum value.
maxnumber100
Maximum value.
stepnumber1
Value increment for thumbs, keyboard input and number fields.
rangebooleanfalse
Enables two thumbs and an ordered pair for v-model.
disabledbooleanfalse
Disables interaction.
readonlybooleanfalse
Prevents pointer and keyboard changes. Thumbs remain focusable; number fields become read-only.
invalidbooleanfalse
Sets aria-invalid and the error style. Does not block form submission by itself.
sizeSliderSize'sm' | 'md' | 'lg''md'
Number-field size, overridden when VInputGroup sets a size.
labelstringnone
Label above the slider, which also names the thumbs. Range thumbs receive distinct start and end names.
hideLabelbooleanfalse
Hides the label visually while keeping it as the thumbs name.
labelPositionFieldLabelPosition'top' | 'start''top'
Places the label above the field or beside it.
hintstringnone
Help text 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.
orientationSliderOrientation'horizontal' | 'vertical''horizontal'
Track direction. Vertical sliders place the minimum at the bottom.
inputsSliderInputsfalse | 'ends' | 'top' | 'bottom'false
Number-field placement: ends, top, bottom, or false to hide them. Range mode adds two fields.
ticksbooleanfalse
Shows step markers, also enabled by labels. Hidden beyond 50 steps.
labelsSliderLabel[]none
Ordered step labels, as strings or icon-and-label objects. Also supplies accessible value text.
tooltipbooleanfalse
Displays the value while a thumb is dragged or focused. Hidden from assistive technology.
formatOptionsIntl.NumberFormatOptionsnone
Intl.NumberFormat options for the tooltip, the number fields and the value thumbs announce.
localestringnone
Language of the written value. Defaults to the library locale.
v-modelSliderValue0
Number or ordered pair with range. Crossing thumbs pushes the other endpoint to keep the pair ordered.

Events

EventType
input[value: SliderValue]
Emits the whole value while a thumb moves.
change[value: SliderValue]
Emits the committed value after thumb interaction or number-field validation.

Types

Types used in the API tables. Import exported types from vectis-ui.

export interface BuiltinIcon {
  name: string
  paths: readonly [string] | readonly [string, string]
}
export type IconRender =
  | { path: string; viewBox?: string }
  | { component: Component; props?: Record<string, unknown> }
  | { src: string }
  | { text: string; class?: string }
  | { class: string }
export type IconSource = string | BuiltinIcon | IconRender
export type SliderLabel = string | { icon: IconSource; label: string }
export type SliderValue = number | [number, number]

CSS variables

TokenValue
--vectis-control-size-slider-track0.375rem
--vectis-control-size-slider-thumb1.25rem
--vectis-control-size-slider-length10rem
--vectis-control-size-slider-field5rem