Slider
Pick a value, or a range with two thumbs, by dragging. The track is 8px and the thumb is 24px with an invisible 44px hit area.
Installation
npx shadcn@latest add @sevenone/sliderUsage
import { Slider } from "@/components/ui/slider"Examples
With the value
Show the value as text next to the label, so people do not have to guess it.
50%
const [value, setValue] = React.useState([50])
<div className="grid gap-3">
<div className="flex items-center justify-between">
<Label id="volume-label">Volume</Label>
<span className="text-sm text-muted-foreground">{value[0]}%</span>
</div>
<Slider value={value} onValueChange={setValue} max={100} step={1} aria-labelledby="volume-label" />
</div>Range
Two thumbs. Name each one with thumbLabels.
<Slider
defaultValue={[25, 75]}
max={100}
step={5}
thumbLabels={["Minimum price", "Maximum price"]}
/>Disabled
<Slider defaultValue={[40]} max={100} disabled aria-label="Brightness" />Accessibility
- Each thumb has the slider role. Name it with aria-label, aria-labelledby or thumbLabels.
- Arrow keys change the value by one step; Page Up and Page Down by more; Home and End go to the ends.
- The thumb border gets thicker on hover and focus, so the focus is easy to see.