Skip to content

Slider ​

A range input that is easy to style.

vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
import styles from './index.module.css';
</script>

<template>
  <Slider.Root :default-value="25">
    <Slider.Control :class="styles.Control">
      <Slider.Track :class="styles.Track">
        <Slider.Indicator :class="styles.Indicator" />
        <Slider.Thumb aria-label="Volume" :class="styles.Thumb" />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>
css
.Control {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 14rem;
  padding-block: 0.75rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
</script>

<template>
  <Slider.Root :default-value="25">
    <Slider.Control class="flex w-56 touch-none items-center py-3 select-none">
      <Slider.Track class="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
        <Slider.Indicator class="bg-neutral-950 select-none dark:bg-white" />
        <Slider.Thumb
          aria-label="Volume"
          class="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
        />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>

Usage guidelines ​

  • Form controls must have an accessible name: Use Slider.Label, or give each Slider.Thumb an aria-label when the slider has no visible label. See Labeling a slider and the forms guide.

Anatomy ​

Import the component and assemble its parts:

vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
</script>

<template>
  <Slider.Root>
    <Slider.Label />
    <Slider.Value />
    <Slider.Control>
      <Slider.Track>
        <Slider.Indicator />
        <Slider.Thumb />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>

Examples ​

Labeling a slider ​

A slider with one thumb and no visible label, such as a volume control, takes its name from aria-label on Slider.Thumb:

vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
</script>

<template>
  <Slider.Root>
    <Slider.Control>
      <Slider.Track>
        <Slider.Indicator />
        <Slider.Thumb aria-label="Volume" />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>

Slider.Label gives the slider a visible label:

vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
</script>

<template>
  <Slider.Root>
    <Slider.Label>Volume</Slider.Label>
    <Slider.Control>
      <Slider.Track>
        <Slider.Indicator />
        <Slider.Thumb />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>

A range slider with a visible label also needs an aria-label on each Slider.Thumb, so that each thumb has a name of its own:

vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
</script>

<template>
  <Slider.Root :default-value="[25, 75]">
    <Slider.Label>Price range</Slider.Label>
    <Slider.Control>
      <Slider.Track>
        <Slider.Indicator />
        <Slider.Thumb aria-label="Minimum price" />
        <Slider.Thumb aria-label="Maximum price" />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>

Range slider ​

To make a range slider, give Slider.Root an array of values. Render one Slider.Thumb for each value in the array.

The thumbCollisionBehavior prop of Slider.Root sets what the thumbs do when they meet during a pointer drag.

vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
import styles from './index.module.css';
</script>

<template>
  <Slider.Root :default-value="[25, 45]">
    <Slider.Control :class="styles.Control">
      <Slider.Track :class="styles.Track">
        <Slider.Indicator :class="styles.Indicator" />
        <Slider.Thumb :index="0" aria-label="Minimum value" :class="styles.Thumb" />
        <Slider.Thumb :index="1" aria-label="Maximum value" :class="styles.Thumb" />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>
css
.Control {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 14rem;
  padding-block: 0.75rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
</script>

<template>
  <Slider.Root :default-value="[25, 45]">
    <Slider.Control class="flex w-56 touch-none items-center py-3 select-none">
      <Slider.Track class="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
        <Slider.Indicator class="bg-neutral-950 select-none dark:bg-white" />
        <Slider.Thumb
          :index="0"
          aria-label="Minimum value"
          class="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
        />
        <Slider.Thumb
          :index="1"
          aria-label="Maximum value"
          class="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
        />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>

Steps ​

The step prop sets the increment of the value. The largeStep prop sets the increment of Page Up, Page Down, and an arrow key with Shift.

400
vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
import styles from './index.module.css';
</script>

<template>
  <Slider.Root
    :class="styles.Root"
    :default-value="400"
    :min="100"
    :max="900"
    :step="100"
    :large-step="200"
  >
    <Slider.Label :class="styles.Label">Font weight</Slider.Label>
    <Slider.Value :class="styles.Value" />
    <Slider.Control :class="styles.Control">
      <Slider.Track :class="styles.Track">
        <Slider.Indicator :class="styles.Indicator" />
        <Slider.Thumb :class="styles.Thumb" />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>
css
.Root {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 14rem;
}

.Label {
  cursor: default;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Value {
  font-size: 0.875rem;
  line-height: 1.25rem;
  text-align: end;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Control {
  box-sizing: border-box;
  display: flex;
  grid-column: span 2;
  align-items: center;
  padding-block: 0.75rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
</script>

<template>
  <Slider.Root
    class="grid w-56 grid-cols-2"
    :default-value="400"
    :min="100"
    :max="900"
    :step="100"
    :large-step="200"
  >
    <Slider.Label class="cursor-default text-sm text-neutral-950 dark:text-white"
      >Font weight</Slider.Label
    >
    <Slider.Value class="text-end text-sm text-neutral-950 dark:text-white" />
    <Slider.Control class="col-span-2 flex touch-none items-center py-3 select-none">
      <Slider.Track class="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
        <Slider.Indicator class="bg-neutral-950 select-none dark:bg-white" />
        <Slider.Thumb
          class="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
        />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>

Marks ​

Render your own tick marks. Put each mark on the track at the percentage of its value in the range.

vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
import styles from './index.module.css';

const MIN = 0;
const MAX = 100;
const MARKS = [0, 25, 50, 75, 100];

function valueToPercent(value: number) {
  return ((value - MIN) / (MAX - MIN)) * 100;
}
</script>

<template>
  <Slider.Root :class="styles.Root" :default-value="40" :min="MIN" :max="MAX">
    <Slider.Control :class="styles.Control">
      <Slider.Track :class="styles.Track">
        <Slider.Indicator :class="styles.Indicator" />
        <div
          v-for="mark in MARKS"
          :key="mark"
          aria-hidden="true"
          :class="styles.Mark"
          :style="{ left: `${valueToPercent(mark)}%` }"
        />
        <Slider.Thumb aria-label="Volume" :class="styles.Thumb" />
      </Slider.Track>
    </Slider.Control>
    <div :class="styles.MarkLabels" aria-hidden="true">
      <span
        v-for="mark in MARKS"
        :key="mark"
        :class="styles.MarkLabel"
        :style="{ left: `${valueToPercent(mark)}%` }"
      >
        {{ mark }}
      </span>
    </div>
  </Slider.Root>
</template>
css
.Root {
  width: 14rem;
}

.Control {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  padding-block: 0.625rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Mark {
  position: absolute;
  top: 50%;
  width: 1px;
  height: 0.5rem;
  background-color: oklch(14.5% 0 0deg);
  transform: translate(-50%, -50%);

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.MarkLabels {
  position: relative;
  height: 1rem;
  -webkit-user-select: none;
  user-select: none;
}

.MarkLabel {
  position: absolute;
  top: 0;
  font-size: 0.75rem;
  line-height: 1rem;
  color: oklch(43.9% 0 0deg);
  white-space: nowrap;
  transform: translateX(-50%);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}
vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';

const MIN = 0;
const MAX = 100;
const MARKS = [0, 25, 50, 75, 100];

function valueToPercent(value: number) {
  return ((value - MIN) / (MAX - MIN)) * 100;
}
</script>

<template>
  <Slider.Root class="w-56" :default-value="40" :min="MIN" :max="MAX">
    <Slider.Control class="flex touch-none items-center py-2.5 select-none">
      <Slider.Track class="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
        <Slider.Indicator class="bg-neutral-950 select-none dark:bg-white" />
        <div
          v-for="mark in MARKS"
          :key="mark"
          aria-hidden="true"
          class="absolute top-1/2 h-2 w-px -translate-x-1/2 -translate-y-1/2 bg-neutral-950 dark:bg-white"
          :style="{ left: `${valueToPercent(mark)}%` }"
        />
        <Slider.Thumb
          aria-label="Volume"
          class="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
        />
      </Slider.Track>
    </Slider.Control>
    <div class="relative h-4 select-none" aria-hidden="true">
      <span
        v-for="mark in MARKS"
        :key="mark"
        class="absolute -translate-x-1/2 text-xs whitespace-nowrap text-neutral-600 dark:text-neutral-400"
        :style="{ left: `${valueToPercent(mark)}%` }"
      >
        {{ mark }}
      </span>
    </div>
  </Slider.Root>
</template>

The marks do not change the values that the thumb can have. To snap the thumb to each mark, set step to the distance between two marks.

Thumb alignment ​

By default, the center of the thumb is on the edge of the control when the value is at min or max, so the thumb goes past the control. With thumbAlignment="edge", the thumb stays in the control, and its edge is on the edge of the control.

vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
import styles from './index.module.css';
</script>

<template>
  <Slider.Root thumb-alignment="edge" :default-value="25">
    <Slider.Control :class="styles.Control">
      <Slider.Track :class="styles.Track">
        <Slider.Indicator :class="styles.Indicator" />
        <Slider.Thumb aria-label="Volume" :class="styles.Thumb" />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>
css
.Control {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 14rem;
  padding-block: 0.75rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
</script>

<template>
  <Slider.Root thumb-alignment="edge" :default-value="25">
    <Slider.Control class="flex w-56 touch-none items-center py-3 select-none">
      <Slider.Track class="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
        <Slider.Indicator class="bg-neutral-950 select-none dark:bg-white" />
        <Slider.Thumb
          aria-label="Volume"
          class="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
        />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>

Vertical ​

Set orientation="vertical" on Slider.Root to make a vertical slider.

vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
import styles from './index.module.css';
</script>

<template>
  <Slider.Root orientation="vertical" :default-value="35">
    <Slider.Control :class="styles.Control">
      <Slider.Track :class="styles.Track">
        <Slider.Indicator :class="styles.Indicator" />
        <Slider.Thumb aria-label="Volume" :class="styles.Thumb" />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>
css
.Control {
  box-sizing: border-box;
  display: flex;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;

  &[data-orientation='vertical'] {
    height: 8rem;
    padding-inline: 0.75rem;
  }
}

.Track {
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }

  &[data-orientation='vertical'] {
    height: 100%;
    width: 0.25rem;
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { Slider } from '@vase-ui/vue/slider';
</script>

<template>
  <Slider.Root orientation="vertical" :default-value="35">
    <Slider.Control
      class="flex touch-none select-none data-[orientation=vertical]:h-32 data-[orientation=vertical]:px-3"
    >
      <Slider.Track
        class="bg-neutral-200 select-none dark:bg-neutral-800 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1"
      >
        <Slider.Indicator class="bg-neutral-950 select-none dark:bg-white" />
        <Slider.Thumb
          aria-label="Volume"
          class="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
        />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</template>

Render on the server ​

The slider reads the text direction of its element. On a right-to-left page that renders on a server, give Slider.Root the attribute dir="rtl", so that the server HTML has each thumb at its place.

API reference ​

Slider.Root ​

Groups all parts of the slider. The slider reads the text direction of its element at the mount, and at each focus, press and key of the user. On a page that changes its direction, bind dir to the root. Renders a <div> element.

Props

PropTypeDefaultDescription
defaultValueValue | undefinedThe value of an uncontrolled slider, at the mount and at a native reset of the form. The default is min.
disabledboolean | undefinedfalseThe user cannot change the value, and the form data has no value.
formstring | undefinedThe id of the form that owns the inputs, for a slider outside that form.
formatIntl.NumberFormatOptions | undefinedThe format of the text of Slider.Value, and of aria-valuetext of each input.
largeStepnumber | undefined10The change for Page Up, Page Down, and Shift with an arrow key.
localeIntl.LocalesArgumentthe locale of the nearest LocaleProvider, else 'en-US'The locale of the text.
maxnumber | undefined100The greatest value. The End key moves the thumb to the largest value of the grid.
minnumber | undefined0The least value. The Home key sets it.
minStepsBetweenValuesnumber | undefined0The least distance between two thumbs, as a number of steps. A thumb stops at its neighbor.
modelValueValue | undefinedThe value. An array makes a range, with one value for each thumb.
namestring | undefinedThe name of each input in the data of a form. The form gets one entry for each enabled thumb.
orientation"horizontal" | "vertical" | undefined'horizontal'The axis of the slider.
stepnumber | undefined1The distance between two values of the grid, which starts at min. An arrow key moves one step. The slider shows a value of the parent at the nearest value of the grid.
thumbAlignment"center" | "edge" | undefined'center'Where a thumb is at min and max: its center at the end of the control, or its edge. CSS places each thumb, also in the server HTML.
thumbCollisionBehaviorThumbCollisionBehavior | undefined'push'What the thumbs do when a drag makes them meet.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: SliderRootState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: SliderRootState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Events

EventArgumentsDescription
valueChange[value: Value extends number ? number : Value, details: SliderRootChangeEventDetails]The user changes the value, also at each move of a drag. details.cancel() keeps the value.
update:modelValue[value: Value extends number ? number : Value]Comes after the change event, unless a listener cancels the change. v-model uses it.
valueCommitted[value: Value extends number ? number : Value, details: SliderRootCommitEventDetails]The user ends an action that changed the value: a key, an input event, or a press.

Exposed

MemberTypeDescription
elementHTMLDivElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-orientation]The orientation of the slider: horizontal or vertical.
[data-disabled]The slider is disabled.
[data-dragging]The user presses the control with a pointer.
[data-valid]The value is valid, in a Field.Root.
[data-invalid]The value is invalid, in a Field.Root.
[data-touched]The focus left the slider one time or more, in a Field.Root.
[data-dirty]The value differs from the first value, in a Field.Root.

Slider.Label ​

An accessible label for the inputs of the slider thumbs. Renders a <label> element for the input of the first thumb. The label also names the root and each input that has no aria-label or aria-labelledby of its own.

Props

PropTypeDefaultDescription
idstring | undefinedThe id of the label. With none, the label has an id of its own.

Slots

SlotSlot propsDescription
default
state: SliderRootState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: SliderRootState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLLabelElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-orientation]The orientation of the slider: horizontal or vertical.
[data-disabled]The slider is disabled.
[data-dragging]The user presses the control with a pointer.
[data-valid]The value is valid, in a Field.Root.
[data-invalid]The value is invalid, in a Field.Root.
[data-touched]The focus left the slider one time or more, in a Field.Root.
[data-dirty]The value differs from the first value, in a Field.Root.

Slider.Value ​

Displays the current value of the slider as text. Renders an <output> element.

Slots

SlotSlot propsDescription
default
state: SliderRootState
values: readonly number[]
formattedValues: readonly string[]
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: SliderRootState
values: readonly number[]
formattedValues: readonly string[]
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLOutputElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-orientation]The orientation of the slider: horizontal or vertical.
[data-disabled]The slider is disabled.
[data-dragging]The user presses the control with a pointer.
[data-valid]The value is valid, in a Field.Root.
[data-invalid]The value is invalid, in a Field.Root.
[data-touched]The focus left the slider one time or more, in a Field.Root.
[data-dirty]The value differs from the first value, in a Field.Root.

Slider.Control ​

The clickable, interactive part of the slider. A press moves the nearest thumb to the pointer, and a drag moves the thumb with the pointer. The inline style touch-action: none stops the scroll of the page at a touch drag. To let the page scroll across a horizontal slider, give the control the style touch-action: pan-y. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: SliderRootState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: SliderRootState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-orientation]The orientation of the slider: horizontal or vertical.
[data-disabled]The slider is disabled.
[data-dragging]The user presses the control with a pointer.
[data-valid]The value is valid, in a Field.Root.
[data-invalid]The value is invalid, in a Field.Root.
[data-touched]The focus left the slider one time or more, in a Field.Root.
[data-dirty]The value differs from the first value, in a Field.Root.

Slider.Track ​

Contains the slider indicator and represents the entire range of the slider. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: SliderRootState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: SliderRootState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLDivElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-orientation]The orientation of the slider: horizontal or vertical.
[data-disabled]The slider is disabled.
[data-dragging]The user presses the control with a pointer.
[data-valid]The value is valid, in a Field.Root.
[data-invalid]The value is invalid, in a Field.Root.
[data-touched]The focus left the slider one time or more, in a Field.Root.
[data-dirty]The value differs from the first value, in a Field.Root.

Slider.Indicator ​

Visualizes the current value of the slider. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: SliderRootState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: SliderRootState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLDivElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-orientation]The orientation of the slider: horizontal or vertical.
[data-disabled]The slider is disabled.
[data-dragging]The user presses the control with a pointer.
[data-valid]The value is valid, in a Field.Root.
[data-invalid]The value is invalid, in a Field.Root.
[data-touched]The focus left the slider one time or more, in a Field.Root.
[data-dirty]The value differs from the first value, in a Field.Root.

Slider.Thumb ​

The draggable part of the slider at the tip of the indicator. The input gets each aria-* attribute, tabindex, autofocus, and the focus, blur and keydown listeners. The thumb element gets each other attribute. Renders a <div> element with a range <input> element in it.

Props

PropTypeDefaultDescription
disabledboolean | undefinedfalseThe user cannot move the thumb, and the form data has no value for it.
getAriaValueText((formattedValue: string, value: number, index: number) => string) | undefinedMakes aria-valuetext of the input.
idstring | undefinedThe id of the input.
indexnumber | undefinedThe index of the value of the thumb. With none, the thumb takes its place among the thumbs. Set it only when the thumbs do not render in the order of their values.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: SliderRootState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: SliderRootState
inputProps: Record<string, unknown>
inputRef: (target: unknown) => void
Renders your element in place of the element of the thumb. Bind props with v-bind and elementRef with :ref. Render the input in your element, or in another place, with v-bind="inputProps" and :ref="inputRef".

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.
inputHTMLInputElement | nullThe range input of the thumb, or null while it is not mounted.

Selectors

SelectorDescription
[data-orientation]The orientation of the slider: horizontal or vertical.
[data-disabled]The slider or the thumb is disabled.
[data-dragging]The user presses the control with a pointer.
[data-valid]The value is valid, in a Field.Root.
[data-invalid]The value is invalid, in a Field.Root.
[data-touched]The focus left the slider one time or more, in a Field.Root.
[data-dirty]The value differs from the first value, in a Field.Root.
:has(:focus-visible)The input of the thumb shows a focus ring.

Differences from Base UI ​

Vase UI ports Slider from Base UI 1.9.0.

API ​

Base UIVase UI
Slider.RootCSS selects :focus-within, and a slot reads state.activeThumbIndex, so the state has no focused, and the part has no data-focused. A native reset emits only update:modelValue, and each change of the user has a native event, so the change reasons have no none. 'edge' needs no script, so thumbAlignment has no 'edge-client-only'.
Slider.LabelCSS selects :focus-within, and a slot reads state.activeThumbIndex, so the state has no focused, and the part has no data-focused. The element is a <label> for the input of the first thumb.
Slider.ValueCSS selects :focus-within, and a slot reads state.activeThumbIndex, so the state has no focused, and the part has no data-focused.
Slider.ControlCSS selects :focus-within, and a slot reads state.activeThumbIndex, so the state has no focused, and the part has no data-focused.
Slider.TrackCSS selects :focus-within, and a slot reads state.activeThumbIndex, so the state has no focused, and the part has no data-focused.
Slider.IndicatorCSS selects :focus-within, and a slot reads state.activeThumbIndex, so the state has no focused, and the part has no data-focused.
Slider.ThumbCSS selects :focus-within, and a slot reads state.activeThumbIndex, so the state has no focused, and the part has no data-focused. A template ref has the input as input, in the place of inputRef. The developer writes each thumb and knows its index, so an aria-label on each thumb takes the place of getAriaLabel, and a class on each thumb takes the place of data-index. aria-valuetext and tabindex are plain attributes that go to the input.

Added in Vase UI ​

PartMemberWhy
Slider.Thumbid propThe id of the input, which has the role slider and takes the focus. A native <label for> names that input.

Behavior ​

Vase UIEvidence
The server HTML of a range slider has the value and the text of the value of each thumb, also when the thumbs have no index prop. A thumb takes its index from the order in which the thumbs render. Base UI needs the index prop on each thumb for a server render, because its list of thumbs fills only after the mount. The server HTML of a slider that has Slider.Label has the for of the label, and the aria-labelledby of each input after the label. The root and an input before the label get their aria-labelledby at the mount. Base UI links the label after the page hydrates.
Slider.Root gives each valueChange listener the native event of the browser, and the first argument is the new value. Each input keeps its own name. Base UI copies the event and gives the copy a target with the fields name and value.
With thumbAlignment="edge", a thumb and its indicator follow the new axis when orientation changes and the elements keep their size. After a change to thumbAlignment="center", a press on the control uses its full width or height. A press on a control with no room to move keeps the value.
With no locale prop, Meter.Root, Progress.Root, Slider.Root and NumberField.Root format their text in the locale of the nearest LocaleProvider, else in en-US. The server and the browser use the same locale, so the text does not change after the hydration. Base UI formats the text of Meter, Progress and Slider in en-US until the hydration, and then in the locale of the browser. It formats the text of Number Field in the default locale of each runtime, so the server and the browser can differ.
Slider.Label is a native <label> whose for is the id of the input of the first thumb. A click on the label gives that input the focus, also in a range slider, as a click on the label of each native control does. Base UI gives no thumb the focus at a click on the label of a range slider.

The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.