Skip to content

Slider

An accessible slider component for selecting numeric values from a range.

Basic Usage

Range Slider (Two Thumbs)

Use an array value to create a range slider with multiple thumbs.

Multi-Range Slider

Create sliders with 3 or more thumbs for complex selections.

Vertical Slider

Custom Min, Max, and Step

With x-model

Current volume:

With Markers

Add visual markers at specific values along the track.

Read-Only State

Disabled State

Formatted Values

With Change Event

API Reference

Component Props

PropTypeDefaultDescription
valuenumber | number[]0Single value or array of values for multiple thumbs
minnumber0Minimum allowed value
maxnumber100Maximum allowed value
stepnumber1Value increment/decrement step
orientation'horizontal' | 'vertical''horizontal'Slider orientation
disabledbooleanfalseWhether the slider is disabled
readOnlybooleanfalseWhether the slider is read-only
namestring-Name for form submission
formatOptionsIntl.NumberFormatOptions-Options for formatting displayed values

Parts

PartDescription
x-slider:rootRoot container element
x-slider:labelLabel element
x-slider:controlTrack container (clickable area)
x-slider:trackBackground track
x-slider:rangeFilled range (from min to value, or between thumbs)
x-slider:thumb="index"Draggable thumb element (index starts at 0)
x-slider:marker="value"Visual marker at a specific value position
x-slider:outputValue display element
x-slider:hidden-input="index"Hidden input for form submission (optional)

Data Attributes

AttributeDescription
data-disabledPresent when slider is disabled
data-orientationCurrent orientation (horizontal or vertical)
data-indexThumb index (on thumb elements)

Events

EventDetailDescription
change{ value, values }Fired when slider value changes

Keyboard Interactions

KeyDescription
ArrowRight / ArrowUpIncrease value by step
ArrowLeft / ArrowDownDecrease value by step
PageUpIncrease value by 10× step
PageDownDecrease value by 10× step
HomeSet to minimum value
EndSet to maximum value
TabMove focus to next/previous thumb

Accessibility

This component follows the WAI-ARIA Slider Pattern:

  • Uses role="slider" on thumb elements
  • Provides aria-valuenow, aria-valuemin, aria-valuemax attributes
  • Supports aria-valuetext for formatted value announcements
  • Implements all required keyboard interactions
  • Manages focus properly between multiple thumbs
  • Prevents thumbs from crossing each other

Styling

The slider is completely unstyled by default. Use the data attributes and parts to style it:

css
/* Track */
[data-part="track"] {
  /* Background track styles */
}

/* Filled range */
[data-part="range"] {
  /* Filled portion styles */
}

/* Thumb */
[data-part="thumb"] {
  /* Thumb styles */
}

/* Disabled state */
[data-disabled] [data-part="thumb"] {
  /* Disabled thumb styles */
}

/* Vertical orientation */
[data-orientation="vertical"] [data-part="control"] {
  /* Vertical slider styles */
}

Tips

  • Use arrays for the value prop to create range sliders with multiple thumbs
  • Thumbs automatically prevent crossing each other
  • Click anywhere on the track to move the nearest thumb to that position
  • The range part automatically positions itself between the first and last thumb
  • For vertical sliders, set appropriate height on the control element
  • Use formatOptions to display currency, percentages, or other formatted values

Built with Alpine.js and inspired by Zag.js