Playground
Change the props and copy the code. The controls come from the component's TypeScript types.
Props
import { Slider } from "@/components/ui/slider";<Slider defaultValue={[40]} aria-label="Volume" />Installation
$ pnpm dlx shadcn@latest add @synccn/sliderFirst time in this project? Connect synccn with one command.
Usage
import { Slider } from "@/components/ui/slider";<Slider defaultValue={[20, 80]} />API reference
Generated from the component's TypeScript types, so it always matches the code.
Slider
Single value or range slider. Pass an array as value for a range.
- value
number[]Controlled value; two numbers make a range.
- defaultValue
number[]Default
[50]Initial value when uncontrolled.
- onValueChange
(value: number[]) => voidCalled with the new value.
- min
numberDefault
0Lowest value.
- max
numberDefault
100Highest value.
- step
numberDefault
1Amount per step.
- disabled
booleanPrevents changes.
- showValue
booleanDefault
falseBubble with the value on hover and focus.
- format
(value: number) => React.ReactNodeDefault
(v) => vFormats the bubble value.
- aria-label
stringAccessible name.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
npm packages
- clsx for cn()
- tailwind-merge for cn()
Keyboard
- →or↑Increase by one step
- ←or↓Decrease by one step
- Page UporPage DownChange by a bigger step
- HomeorEndJump to the minimum or maximum
Accessibility
- Each thumb has role slider with aria-valuenow, min and max. Pass aria-label to name it.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: slider
- ARIA attributes: aria-label, aria-valuemax, aria-valuemin, aria-valuenow
- Keys handled: ArrowUp, ArrowDown, ArrowLeft, ArrowRight, Home, End, PageUp, PageDown
- Shows a visible focus ring for keyboard users