Skip to content

React Range Slider

A glass React slider that picks a single value or a range by dragging, clicking the track or pressing the arrow keys. Use Slider as a React slider component for a volume or brightness control where people want to drag and hear or see the change as they go, and exact digits matter less than feel.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/slider.json
Brightness
10

Single value and range

Volume
60
Price range
200 – 800

Files to copy

5 folders · 4 files · 3 packages
From theme/src/
  • components/slider/
  • components/field/
  • hooks/use-latest.ts
  • lib/{cn.ts, form.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/slider.jsonRegistry item: slider. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx tailwind-merge

Step, bounds and states

Temperature
21.5
Locked
40

Props

PropTypeDefaultDescription
aria-describedbystringNoneIds of elements that describe the field, merged with the control's own description and error ids.
aria-invalidboolean | "true" | "false"NoneMarks the field as invalid (also set automatically when error is shown).
onBlurFocusEventHandler<HTMLElement>NoneCalled when focus leaves the control (not when it moves between the control's own parts).
namestringNoneField name, used for native form submission and by form libraries.
disabledbooleanNoneDisables the slider so it cannot be moved.
valuenumber | number[]NoneTakes one number, or two for a range.
defaultValuenumber | number[]NoneSets the starting value when uncontrolled.
onValueChange((value: number | number[]) => void)NoneCalled on every change while dragging or using the keyboard.
onValueCommitted((value: number | number[]) => void)NoneCalled once when a change ends: the pointer is released, or a key press is done. Use it to save, instead of saving on every step.
minnumber0Lowest selectable value, the value at the left end of the track; keep it below max.
maxnumber100Highest selectable value, the value at the right end of the track; keep it above min.
stepnumber1Sets the size of one step.
largeStepnumber10 (a change of 10 in the value, not ten steps)Sets the step for PageUp / PageDown and Shift + arrows.
minStepsBetweenValuesnumber0For a range: the smallest allowed gap between two thumbs, in steps.
idstringNoneId of the slider root (a label or a form library can point at it).
formstringNoneId of a <form> element to submit with when the slider is outside it.
labelReactNodeNoneText above the track, also the slider's accessible name.
showValuebooleantrueShow the current value(s) next to the label.
showBubblebooleantrueShow a bubble with the value above the thumb while dragging (useful on touch, where a finger covers the thumb).
aria-labelstringNoneLabel for screen readers when there is no visible label.
aria-labelledbystringNoneId of an element that names the slider (instead of label).
labelsPartial<SliderLabels>defaultSliderLabelsEvery string, for translation: the names of the two range thumbs. Every other string, for translation: labels={{ minimum: "…" }}; omitted keys keep the English of defaultSliderLabels. All 2 keys of SliderLabels are listed in the key table under the props table.
classNamestringNoneAdds extra classes to the outer element.
SliderLabels keys and English defaults (2)
Pass any key in labels; the rest keep the defaults of defaultSliderLabels.
KeyEnglish default
minimumMinimum
maximumMaximum

Keyboard

KeysAction
Tab/Shift + TabFocus each thumb in turn.
Arrow keysChange the value by one step.
Page Up/Page DownChange the value by 10 by default (set with largeStep).
Home/EndJump to the minimum or maximum.

Accessibility

  • Each thumb is role="slider" with aria-valuenow, aria-valuemin and aria-valuemax; a range slider has one thumb per value.
  • The label names the group; the value text is announced as it changes.
  • The track is 44 px tall on touch screens and its edge has a 3:1 border; a value bubble shows above the thumb while dragging.

All exports on this page

  • Slider — A slider for picking a number (volume, price) or a range between two numbers.
  • defaultSliderLabels — The English SliderLabels used when labels is omitted; a partial labels prop is merged over it.

When to use Slider

  • Use Slider for a price range filter, a zoom level or an audio volume, where a thumb on a track is quicker than typing; pair it with a visible value when the exact number matters. For a dual range slider in Tailwind, pass two values and the component draws two thumbs on one track.
  • Use two values for a price range filter on a product list, with minStepsBetweenValues keeping the thumbs from crossing and the bubble showing the value above the thumb while dragging.
  • Use onValueCommitted to save a setting once when the drag or key press ends, rather than firing a request on every step of onValueChange.
  • Skip it when people must enter an exact figure, where NumberField fits, or when there are three or four named choices, where SegmentedControl or RadioGroup is clearer.
  • Pair it with NumberField for a typed fallback, Field to describe the range, and Button to apply the filter after the range is chosen.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .