Slider

A headless, accessible slider with single- or multi-thumb selection, keyboard support, and horizontal/vertical orientation.

Features

  • Horizontal or vertical
  • Single or multi-thumb
  • Controlled or uncontrolled
  • Keyboard and pointer support
  • Headless

Installation

npm install @ariaui/slider

Examples

Three playgrounds aligned with the legacy doc: an uncontrolled single thumb (100–200 with a CSS tooltip), a two-thumb range on 0–100, and a vertical track.

Shared class strings live in sliderExampleTokens.ts; each block is a static defaultValue tree so the generated snippet stays copy-pasteable.

Uncontrolled

Single thumb with a static defaultValue. This docs variant uses the thumb's aria-valuenow as a CSS tooltip so the snippet stays copy-pasteable without extra state.

Preview

No preview output yet.

live.tsxReady

Controlled

Drive the slider from React state with value and onValueChange, while rendering the current value next to the thumb state.

Preview

No preview output yet.

live.tsxReady

Disabled

Set isDisabled on the root to lock every thumb and expose disabled state attributes for styling.

Preview

No preview output yet.

live.tsxReady

Multi-thumb

Two thumbs share the same track to create a range. This example starts at [30, 70] and uses each thumb's aria-valuenow as a CSS tooltip.

Preview

No preview output yet.

live.tsxReady

Custom Tooltip

getValueText maps the numeric value to aria-valuetext, and the thumb tooltip reads that attribute for a custom visible label.

Preview

No preview output yet.

live.tsxReady

Vertical

Set orientation="vertical" on the root to switch axes. The track becomes a tall rail while the range fill and thumb labels adapt to the vertical layout.

Preview

No preview output yet.

live.tsxReady

Vertical Multi-thumb

Combine orientation="vertical" with two thumbs to select a vertical range. The thumb tooltips read from aria-valuenow, so dragging updates the visible values.

Preview

No preview output yet.

live.tsxReady

Anatomy

tsx
import * as Slider from "@ariaui/slider";

export default function Example() {
  return (
    <Slider.Root>
      <Slider.Track>
        <Slider.Range />
        <Slider.Thumb />
      </Slider.Track>
    </Slider.Root>
  );
}

API Reference

Root

Slider context provider and state container. Handles controlled/uncontrolled values, step constraints, and orientation.

PropTypeDefault
value
number | number[]
defaultValue
number | number[]min
onValueChange
(value: number | number[]) => void
min
number0
max
number100
step
number1
minStepsBetweenThumbs
number0
orientation
'horizontal' | 'vertical''horizontal'
isDisabled
booleanfalse
getValueText
(value: number) => string
name
string
AttributeValues
data-orientation'horizontal' | 'vertical'
data-disabledpresent when disabled

Track

Background rail that hosts the Range and Thumbs. Clicks and drags on the track move the nearest thumb.

AttributeValues
data-orientation'horizontal' | 'vertical'
data-disabledpresent when disabled

Range

Filled portion of the Track between `min` (or the previous thumb) and the current thumb value.

AttributeValues
data-orientation'horizontal' | 'vertical'
data-disabledpresent when disabled

Thumb

Draggable handle that represents a value. Render one Thumb per value in multi-thumb mode and pass `index`.

PropTypeDefault
index
number0
AttributeValues
role'slider'
aria-valuenowcurrent value of the thumb
aria-valueminmin
aria-valuemaxmax
aria-valuetextgetValueText(value) when provided
aria-orientation'horizontal' | 'vertical'
data-activetrue while dragging or focused
data-disabledpresent when disabled

Keyboard

ShortcutAction
TabMove focus to the next thumb (or away from the slider).
Shift+TabMove focus to the previous thumb.
/Increase the focused thumb by one step.
/Decrease the focused thumb by one step.
PageUpIncrease the focused thumb by a larger increment.
PageDownDecrease the focused thumb by a larger increment.
HomeSet the focused thumb to `min`.
EndSet the focused thumb to `max`.

Accessibility

Slider follows the WAI-ARIA Slider pattern (or multi-thumb Slider pattern when more than one Thumb is present):

  • Each Thumb renders with role="slider" and exposes aria-valuenow, aria-valuemin, aria-valuemax, and aria-orientation.
  • Provide getValueText on Root to deliver meaningful aria-valuetext values (e.g. "$25.00" or "25 percent") — especially important when the raw number isn't self-descriptive.
  • Always label the slider. Pass aria-label or aria-labelledby on Root, or wire up an external <label> to the thumb via aria-labelledby.
  • Keyboard users get full control: arrow keys for fine adjustments, Page Up / Page Down for coarse steps, Home / End for the range bounds, and Tab to move between thumbs.
  • minStepsBetweenThumbs prevents multi-thumb sliders from crossing or overlapping without explicit intent.
  • When isDisabled is true, data-disabled is set on every part for styling and pointer and keyboard interactions are disabled.
Previous
Skeleton