shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A slider picks a number by dragging a thumb along a track, or a range with two thumbs, where the position says more than the digits: volume, brightness, a price band in a search filter. The arrow keys move it one step at a time.
When the exact figure matters, such as a quantity or a sum of money, use a Number Input. For an angle, a dial or a knob, see the Angle Slider and the Circular Slider.
Installation
Anatomy

Usage
import { Slider } from "@/components/ui/slider";const SliderDemo = () => (
<Slider
aria-label="Volume"
className="mx-auto w-full max-w-xs"
defaultValue={[75]}
max={100}
step={1}
/>
);Accessibility
Each thumb holds a visually hidden <input type="range">, so a screen reader announces it as a slider with its value, and the slider is a group around the thumbs. A SliderLabel inside Slider names every thumb. With no visible label, pass aria-label to Slider, which this component puts on every thumb, or getAriaLabel to name each thumb of a range by its index.
When the number needs a unit to make sense, such as 12 months, getAriaValueText sets the words a screen reader says for it.
- Arrow Right
- Increases the value by one step, in either orientation. In a horizontal slider that reads right to left, it decreases it.
- Arrow Left
- Decreases the value by one step, in either orientation. In a horizontal slider that reads right to left, it increases it.
- Arrow Up
- Increases the value by one step.
- Arrow Down
- Decreases the value by one step.
- Page Up
- Increases the value by
largeStep, ten steps unless you set it. - Page Down
- Decreases the value by
largeStep. - Shift+Arrow Up
- Increases the value by
largeStep, as Shift with the Right arrow does. - Shift+Arrow Down
- Decreases the value by
largeStep, as Shift with the Left arrow does. - Home
- Sets the value to its minimum, or in a range, as low as the thumb before it allows.
- End
- Sets the value to its maximum, or in a range, as high as the thumb after it allows.
Demos
Range
Two thumbs start at 25 and 50 and move in steps of 5, and the filled stretch between them is the selection: a price band, a time window, an age range. Use two thumbs when both ends are the person's choice. A thumb stops when it meets the other one.
Multiple
Three thumbs at 10, 20 and 70 move in steps of 10, and the fill runs from the first to the last. Use more than two when the track is cut into bands, such as the thresholds between low, medium and high, rather than one span. Each extra thumb is one more decision for the person, so add it only when the bands need it.
Vertical
Two sliders with orientation set to vertical and the class h-40, one at 50 and one at 25, fill from the bottom. A vertical slider takes the height it is given, so without one it has nowhere to travel. Use it beside something tall, like a mixer channel or a zoom control, where a horizontal track would widen the row.
Controlled
A Temperature slider from 0 to 1 in steps of 0.1 holds two thumbs, at 0.3 and 0.7, in state, and the SliderValue beside its SliderLabel prints both as they move. Control the value when it shows elsewhere, drives a chart or saves while the thumb is still down. When only the final value matters, an uncontrolled slider and its end-of-drag callback are less code.
Disabled
Setting disabled holds the thumb at 50 and fades the track, and neither dragging nor the arrow keys move it, since the thumb leaves the tab order. Keep a disabled slider when a parent switch or the plan has turned the setting off and its last value still tells people something. When the setting doesn't apply at all, remove the slider.
RTL
One thumb at 75 in a Direction provider set to right to left, with dir set to rtl on Slider too. UI SDK reads the direction from the page's CSS, which either one sets, so the track fills from the right, dragging follows the mirrored track, and the Right arrow lowers the value, which is still 75 out of 100. Use this on a page in Arabic or Hebrew.
FAQ
How do I make a range Slider with two thumbs in React?
Give it two values instead of one, such as defaultValue set to [25, 50]. The slider draws one thumb per entry, and the fill runs between them, as in the Range demo.
A thumb stops when it meets the other one, and UI SDK has no option to let it push or cross. Set minStepsBetweenThumbs to keep a gap of that many steps between them, and Home and End then stop at that gap too.
How do I control the Slider value in React?
Keep the array in state, pass it as value and update it in onValueChange. Its first argument is the new value, an array when you passed one, and the Controlled demo copies it into state.
An array draws one thumb per entry. A plain number, or no value at all, draws a single thumb, and then onValueChange receives a number rather than an array.
How do I run code only when the user releases the Slider?
Use onValueCommit. It fires once when the pointer lifts or the key comes up, so holding an arrow key commits only once, and only if the value changed. onValueChange fires on every step of a drag.
That is the place to save a setting or send a filtered search, so a request doesn't go out for each pixel the thumb moves.
How do I set the min, max and step of a Slider?
Set min, max and step on Slider. They default to 0, 100 and 1, and step can be a fraction, such as 0.1 in the Controlled demo.
Page Up, Page Down and Shift with an arrow move by largeStep, ten steps unless you set it.
How do I make a vertical Slider?
Set orientation to vertical and give the slider a height, such as the h-40 class in the Vertical demo. A vertical track fills the height it is given, so in a container with no height it has nowhere to go.
The Up and Down arrows move the thumb, and Left and Right work too.
Does the UI SDK Slider submit its value in a form?
Yes. Give Slider a name, and a hidden input beside it submits the value: a number for one thumb, and one entry such as 25/50 for a range, so split it on the slash on the server. Resetting the form puts the thumbs back where they started.
A slider with disabled set sends nothing, as with any disabled field.
How do I label a Slider for screen readers?
Put a SliderLabel inside Slider, and every thumb is named by it, as in the Controlled demo. With no visible label, pass aria-label to Slider, which this component puts on every thumb. For a range, getAriaLabel receives each thumb's index and returns its name.
Add getAriaValueText when the number alone means little, so a screen reader says 12 months rather than 12.
How do I show the current value next to a Slider?
Put a SliderValue inside Slider. It prints the current value on its own, formatted by format on Slider, with the values of a range joined by an en dash, and getAriaValueText changes only what a screen reader hears, never this text. Give it children to show something else from your state, as the Controlled demo does with both values joined by a comma.
A label and its value usually share one row above the track, so wrap the two in a flex row and push the value to the end, as the Controlled demo does with its readout.
API Reference
Slider
<div> data-slot="slider"
value?Value
The value: a number, or one number per thumb. Pass it to control the slider.
defaultValue?Value
The value at first: a number, or one number per thumb, like [20, 80].
onValueChange?(value: Value, details: SliderValueChangeDetails) → void
Runs while the value changes: on every step of a drag or a key.
- Type
(value: Value, details: SliderValueChangeDetails) → void- Parameters
value– Valuedetails– SliderValueChangeDetails- Returns
void
controller?{ getValue: () → Value; setValue(value: Value, options?: SliderChangeOptions): boolean; focus: (thumb?: number) → void; }
Moves the slider from anywhere. Create one with createSliderController().
- Type
{ getValue: () → Value; setValue(value: Value, options?: SliderChangeOptions): boolean; focus: (thumb?: number) → void; }
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Disables it like a native control: thumbs can't be focused or moved, and nothing is submitted.
form?string
The id of a form to belong to, when it isn't inside that form.
format?NumberFormat
How values read, for screen readers and SliderValue: Intl.NumberFormat options, like { style: "currency", currency: "EUR" }, or a function of the value.
getAriaLabel?(index: number) → string
Names each thumb, by its index. Wins over the slider's aria-label.
- Parameters
index– number- Returns
string
getAriaValueText?( formattedValue: string, value: number, index: number ) → string
What a screen reader says for a thumb's value.
- Type
( formattedValue: string, value: number, index: number ) → string- Parameters
formattedValue– stringvalue– numberindex– number- Returns
string
largeStep?number
How far Page Up, Page Down and Shift with an arrow key move.
- Default
10 steps
locale?string
The locale values are formatted in. Defaults to the page's lang, or the browser's language without one, once the page is interactive. Server markup uses English until then, so it never disagrees with the client.
max?number
The highest value. When the steps from min don't land on it, the highest step below it is the end.
- Default
100
min?number
The lowest value.
- Default
0
minStepsBetweenThumbs?number
How many steps apart neighbouring thumbs stay. Thumbs never pass each other. UI SDK's default: 0.
- Default
minStepsBetweenValues
minStepsBetweenValues?number
Base UI's name for minStepsBetweenThumbs.
name?string
The name it submits under: the number, or a range as "start/end". Without one, it submits nothing.
onValueCommit?(value: Value, details: SliderValueCommitDetails) → void
Runs once an interaction that changed the value ends. For saving.
- Type
(value: Value, details: SliderValueCommitDetails) → void- Default
onValueCommitted- Parameters
value– Valuedetails– SliderValueCommitDetails- Returns
void
onValueCommitted?(value: Value, details: SliderValueCommitDetails) → void
Base UI's name for onValueCommit.
- Type
(value: Value, details: SliderValueCommitDetails) → void- Parameters
value– Valuedetails– SliderValueCommitDetails- Returns
void
orientation?"horizontal" | "vertical"
The slider's axis. Vertical sliders grow upward.
- Type
"horizontal" | "vertical"- Default
"horizontal"
readOnly?boolean
Keeps it focusable and submitted, but stops drags, keys and screen reader adjustments from changing it.
required?boolean
Marks it required, with data-required. A slider always has a value, so it never blocks a form.
step?number
How far one step moves, from min.
- Default
1
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
data-disabled?string
Present when disabled, by its own prop or a <fieldset>.
data-dragging?string
Present while a thumb is being dragged.
data-orientation"horizontal" | "vertical"
The slider's axis.
- Type
"horizontal" | "vertical"
--slider-thumb-sizestringSliderLabel
debug?boolean
Logs every state change with its reason to the console, in development builds.
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
SliderValue
<output> data-slot="slider-value"
children?React.ReactNode
Replaces the formatted value, a range joined with an en dash.
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
data-disabled?string
Present when disabled, by its own prop or a <fieldset>.
data-dragging?string
Present while a thumb is being dragged.
data-orientation"horizontal" | "vertical"
The slider's axis.
- Type
"horizontal" | "vertical"











