Slider

A control for selecting a value or range from within a given range.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/slider.json

Usage

import { Slider } from "@/components/ui/slider"

Examples

Default

A single value. defaultValue is an array even with one thumb, and the control carries no visible label, so give it an aria-label.

Range

Two values from one control: pass two numbers and you get two thumbs. Set minStepsBetweenThumbs to stop them crossing or landing on top of each other.

API Reference

PropTypeDefaultDescription
defaultValuenumber[]NoneInitial value when uncontrolled. One thumb renders per entry, so [25, 75] creates a range slider.
valuenumber[]NoneControlled value. Use with onValueChange.
onValueChange(value: number[]) => voidNoneCalled with the new value as a thumb is dragged.
onValueCommit(value: number[]) => voidNoneCalled once the user finishes an interaction, useful for skipping updates on every tick of a drag.
minnumber0The minimum value of the range.
maxnumber100The maximum value of the range.
stepnumber1The granularity each thumb snaps to.
minStepsBetweenThumbsnumber0Minimum gap (in steps) enforced between thumbs in a range slider.
orientation"horizontal" | "vertical""horizontal"Layout direction. Vertical sliders get an 11rem minimum height.
invertedbooleanfalseReverses the slider's direction so the range fills from the opposite end.
disabledbooleanfalseDisables interaction and dims the slider.
namestringNoneName submitted with its owning form, via a hidden input per thumb.
defaultValuenumber[]Initial value when uncontrolled. One thumb renders per entry, so [25, 75] creates a range slider.
valuenumber[]Controlled value. Use with onValueChange.
onValueChange(value: number[]) => voidCalled with the new value as a thumb is dragged.
onValueCommit(value: number[]) => voidCalled once the user finishes an interaction, useful for skipping updates on every tick of a drag.
minnumber = 0The minimum value of the range.
maxnumber = 100The maximum value of the range.
stepnumber = 1The granularity each thumb snaps to.
minStepsBetweenThumbsnumber = 0Minimum gap (in steps) enforced between thumbs in a range slider.
orientation"horizontal" | "vertical" = "horizontal"Layout direction. Vertical sliders get an 11rem minimum height.
invertedboolean = falseReverses the slider's direction so the range fills from the opposite end.
disabledboolean = falseDisables interaction and dims the slider.
namestringName submitted with its owning form, via a hidden input per thumb.