Slider

A slider allows a user to select one or more values within a range

Usage

<script setup lang="ts">
import { Slider } from '@hareui/vue'
</script>
30
<script setup lang="ts">import { Slider } from '@hareui/vue'</script><template>  <Slider class="w-full max-w-xs" label="Volume" :default-value="30" /></template>

Anatomy

Slider renders a Label, an output showing the formatted value, and a track holding the fill and one thumb per value. A number value renders one thumb; an array renders one thumb per entry (a two-element array is a range slider).

<template>
  <Slider label="…" :default-value="[25, 75]">
    <template #label />                          <!-- Label content -->
    <template #output="{ values, formatted }" /> <!-- output content (default: formatted values joined by ' – ') -->
  </Slider>
</template>
ui keydata-slotElement
baseslider<div> root
labellabelLabel (iff label / #label)
outputslider-output<output>
trackslider-track<span>
fillslider-fill<span>
thumbslider-thumb<span role="slider">, one per value

Examples

Disabled

30
<script setup lang="ts">import { Slider } from '@hareui/vue'</script><template>  <Slider disabled class="w-full max-w-xs" label="Volume" :default-value="30" /></template>

Vertical

30
<script setup lang="ts">import { Slider } from '@hareui/vue'</script><template>  <div class="flex h-64 items-center justify-center">    <Slider class="h-full" label="Volume" :default-value="30" orientation="vertical" />  </div></template>

Range

$100.00 – $500.00
<script setup lang="ts">import { Slider } from '@hareui/vue'</script><template>  <Slider    class="w-full max-w-xs"    label="Price Range"    :default-value="[100, 500]"    :format-options="{ currency: 'USD', style: 'currency' }"    :max="1000"    :min="0"    :step="50"  /></template>

Controlled Value

Control the value with v-model. change-end fires with the final value when a drag or key press commits it.

25

Current value: 25

<script setup lang="ts">import { Slider } from '@hareui/vue'import { ref } from 'vue'const value = ref(25)</script><template>  <div class="flex w-full max-w-xs flex-col gap-4">    <Slider v-model="value" label="Volume" />    <p class="text-sm text-muted">      Current value: {{ value }}    </p>  </div></template>

Custom Value Formatting

Use format-options to format the displayed value. This example formats it as USD.

$60.00
<script setup lang="ts">import { Slider } from '@hareui/vue'</script><template>  <Slider    class="w-full max-w-xs"    label="Price"    :default-value="60"    :format-options="{ currency: 'USD', style: 'currency' }"  /></template>

Custom Output

Use the #output slot to control how the selected values are shown.

25 – 75
<script setup lang="ts">import { Slider } from '@hareui/vue'</script><template>  <Slider class="w-full max-w-xs" label="Range" :default-value="[25, 75]">    <template #output="{ formatted }">      {{ formatted.join(' – ') }}    </template>  </Slider></template>

Render Function

30
<script setup lang="ts">import { Slider } from '@hareui/vue'</script><template>  <!-- Attributes fall through to the root element (HeroUI's `render` prop) -->  <Slider class="w-full max-w-xs" data-custom="foo" label="Volume" :default-value="30" /></template>

Attributes such as data-* fall through to the root element.

Customization

Tailwind CSS

40
<script setup lang="ts">import { Slider } from '@hareui/vue'</script><template>  <Slider    class="w-full max-w-xs"    label="Brightness"    :default-value="40"    :ui="{      label: 'font-medium text-foreground',      output: 'text-xs text-muted tabular-nums',      track: 'bg-default',      fill: 'bg-accent',      thumb: 'bg-accent after:bg-accent-foreground',    }"  /></template>

Global Configuration

app.use(createHareUI({
  ui: { slider: { slots: { output: 'text-muted', thumb: 'rounded-full' } } },
}))

Styling Reference

Slots

  • base → [data-slot="slider"] – grid with the label and output on the first row and the track below (vertical: output, track, label stacked)
  • output → [data-slot="slider-output"] – formatted value(s)
  • track → [data-slot="slider-track"] – track; transparent borders leave room for the thumb at the edges
  • fill → [data-slot="slider-fill"] – selected part of the track
  • thumb → [data-slot="slider-thumb"] – draggable thumb

Interactive States

  • Disabled: [data-disabled] on the slider and thumbs
  • Vertical: [data-orientation="vertical"]
  • Dragging: [data-dragging="true"] on the thumb being dragged
  • Focus: :focus-visible on the thumb
  • Fill edges: [data-fill-start="true"] / [data-fill-end="true"] on the track when the fill reaches the start or end

API Reference

Props

PropTypeDefaultDescription
modelValuenumber | number[]-The current value(s). Bind with v-model. A plain number renders a single thumb; an array renders one thumb per value (e.g. a two-element array for a range slider).
defaultValuenumber | number[]0The initial value(s) when uncontrolled (no v-model).
minnumber0The slider's minimum value.
maxnumber100The slider's maximum value.
stepnumber1The amount the value changes per step.
formatOptionsIntl.NumberFormatOptions-Formatting options for the displayed value label (Intl.NumberFormat).
localestring-The BCP 47 locale used to format the value label. Defaults to the browser locale.
orientation"horizontal" | "vertical""horizontal"The axis the slider is laid out along.
labelstring-The slider's label.
disabledbooleanfalseWhether the slider is disabled.
namestring-The name of the slider, used when submitting an HTML form.
requiredbooleanfalseWhether a value is required before form submission.
idstring-The id of the slider. Generated when omitted.
uiComponentSlots<{ slots: { base: string[]; label: string; output: string[]; track: string[]; fill: string[]; thumb: string[]; }; }>-Per-slot class overrides.

Slots

SlotPropsDescription
labelanyThe label content. Replaces the label prop.
output{ values: number[]; formatted: string[]; }The output content, showing the formatted current value(s). Replaces the default ' – '-joined format.

Emits

EventPayloadDescription
update:modelValue[value: number | number[] | undefined]-
changeEnd[value: number | number[]]-

Accessibility

  • Implements the ARIA slider pattern: each thumb is a role="slider" with aria-valuenow, aria-valuemin and aria-valuemax
  • Keyboard: Arrow keys step by step; Page Up / Page Down and Shift + Arrow step by 10 × step; Home / End jump to min / max
  • label names the slider through aria-labelledby; without one, pass aria-label
  • With name, a hidden input submits the value with a form
  • Right-to-left layouts are supported

On this page

No Headings