Slider
Pick a value within a range by dragging a thumb along a track.
Description
Slider is built on the Radix Slider primitive. Drag the thumb along the track to set a value between min and max; the filled portion of the track shows the current value. It ships in two colors (variant primary / neutral) and three sizes (size md / sm / xs).
Reach for it when the relative position of a value reads faster than the exact number — volume, brightness, opacity, a value within a known range. When the user needs to type or precisely step an exact number, use Input (type="number") or InputStepper instead. For a binary on/off, use Switch.
There is no built-in label — pair the slider with a Label (via htmlFor / id) or an aria-label so it announces its purpose.
Installation
Usage
value and defaultValue are number arrays (a Radix convention), even for a single thumb: pass [50], not 50.
Examples
Sizes
size scales the track height and thumb together. Set it on the Slider itself.
Controlled
Pass value and onValueChange to drive the slider from your own state — useful when other UI needs to react to the value or when you display it. Omit them (use defaultValue) for a simple uncontrolled slider. onValueChange receives a number[].
Accessibility
Built on the Radix Slider primitive, so the thumb is role="slider" with aria-valuemin / aria-valuemax / aria-valuenow, and it is keyboard operable.
ARIA notes:
- There is no built-in label. Add a
Label(htmlFor+idon the slider) or anaria-labelso the thumb announces what it controls. valuereflects toaria-valuenow; providearia-valuetext(Radix passthrough) when the raw number isn't self-explanatory (e.g. a currency or percentage).
Styling
Tailwind override: pass className to merge Tailwind classes with the component's CVA classes (via cn()). It lands on the slider root, so width utilities work there.
Data slots and attributes: the component sets these for CSS targeting.
data-slot="slider"on the root,data-slot="slider-track"on the track,data-slot="slider-range"on the filled range,data-slot="slider-thumb"on the thumb.data-variant="<variant>"anddata-size="<size>"on the root.- Radix sets
data-disabledanddata-orientationon the relevant elements.
Related Components
- Input: use this (with
type="number") when the user needs to type or read an exact value rather than drag. - InputStepper: use this to nudge a number up/down in fixed steps with explicit +/- controls.
- Switch: use this for a binary on/off rather than a value along a range.
API Reference
Slider
Wraps Radix Slider.Root, so its props (min, max, step, disabled, orientation, aria-*, …) are accepted.