Slider
Forms
Input
Interactive slider with single value or range selection. Ideal for volume controls, price ranges, and numeric settings.
Preview
Drag the slider to adjust values
65
Variants
Single value and range selection modes
Single Value (default)
65
Range Selection
20 - 80
With Min/Max Labels
Display minimum and maximum values
75
Custom Step
Control step increments
Step: 0.5
3
Step: 25
50
Custom Range
Set custom min and max values
Price ($100-$5000)
500
Temperature (-20°C to 50°C)
22
States
Different states for various use cases
Default
50
Disabled
50
Props
Slider component API reference
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | — | Current slider value (controlled) |
defaultValue | number | 50 | Initial value (uncontrolled) |
onChange | (value: number) => void | — | Callback when value changes |
min | number | 0 | Minimum value |
max | number | 100 | Maximum value |
step | number | 1 | Step increment |
label | string | — | Label text |
showValue | boolean | true | Display current value |
showMinMax | boolean | false | Display min/max labels |
disabled | boolean | false | Disable interaction |
variant | 'default' | 'range' | 'default' | Slider type |
rangeValue | [number, number] | — | Range values (for range variant) |
onRangeChange | (value: [number, number]) => void | — | Range change callback |
Usage
Import and implementation example
import { Slider } from '@/components/ui/slider'
export default function Example() {
const [value, setValue] = useState(50)
const [range, setRange] = useState<[number, number]>([20, 80])
return (
<>
{/* Basic slider */}
<Slider
value={value}
onChange={setValue}
label="Volume"
showValue
/>
{/* Range slider */}
<Slider
variant="range"
rangeValue={range}
onRangeChange={setRange}
min={0}
max={1000}
step={10}
/>
{/* With custom range and step */}
<Slider
label="Temperature"
min={-20}
max={50}
step={5}
showMinMax
/>
{/* With labels */}
<Slider
label="Brightness"
defaultValue={75}
showValue
showMinMax
/>
</>
)
}Features
Built-in functionality
- Single & range modes: Select single value or range with two thumbs
- Custom step: Integer or decimal step increments
- Custom range: Set min and max boundaries
- Value display: Show current value and min/max labels
- Drag interaction: Smooth drag behavior on track and thumb
- Click to set: Click anywhere on track to set value
- Controlled mode: Support for controlled and uncontrolled usage
- Dark mode: Full dark mode support
Accessibility
Accessibility considerations
ARIA Attributes
Uses role="slider" for thumb elementsaria-valuemin, aria-valuemax, aria-valuenowaria-orientation indicates horizontal layoutKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Focus the slider thumb |
| Arrow Left/Right | Decrease/increase by step |
| Home | Set to minimum value |
| End | Set to maximum value |
Notes
- Label properly associated with slider
- Value announced on change
- Disabled state prevents interaction
- Focus ring visible on keyboard focus