Slider
Sets a value in a range by dragging, when position matters more than the exact number.
When to use
- Set a value in a range where the rough position matters more than the exact number: a match threshold, a volume, a zoom level.
- Pick a range with two thumbs, such as a minimum and maximum age.
When not to use
- An exact number, or a range wider than a few hundred steps: use Input with
type="number". - A handful of named levels: use Radio Group or Toggle Group.
Install
npx shadcn@latest add @clinia/slider60%
Anatomy
- 1Track
data-slot="slider-track"bg-input · h-2 - 2Range
data-slot="slider-range"bg-primary - 3Thumb
data-slot="slider-thumb"ring-input · has-focus-visible:ring-ring
Clinia rules
- The track is the
inputtoken and the filled range isprimary, so both clear 3:1. Trust only appears in the thumb's hover and focus halo. - Always show the current value as text beside the label. The thumb position alone is not a value.
- Pass
defaultValueorvalueas an array. With neither, the slider renders two thumbs, atminandmax.
Do and don't
60%
States
single
range
disabled
vertical
focus
Focus cells apply the component's focus-visible classes statically. Toggle the site theme to review both themes.
Accessibility
Built in
- When the thumb has keyboard focus it shows a solid 2px Trust ring with an offset. Hover adds a wider halo.
- Each thumb is a native range input. Arrow keys move one
step, Shift+Arrow and Page Up or Page Down movelargeStep(10 by default), and Home and End jump to the ends.
Your responsibility
- Name the slider:
aria-labelonSlider, or aLabelwhoseidthe slider references witharia-labelledby. ALabelwithout a target names nothing. - For a range, give each thumb its own name, such as
Minimum ageandMaximum age. - If the number needs a unit, pass
getAriaValueTextso a screen reader hears60 percent, not just60.
How to test
- Press Tab to reach the thumb: the focus halo appears around it.
- Press Arrow Right: the value goes up by one step and the visible value updates. Shift+Arrow Right jumps by ten.
- Press Home, then End: the thumb jumps to the minimum, then the maximum.
- With a screen reader, it announces the slider's name and its current value.
API
Every prop comes from Base UI Slider.
Related