Range slider input component with customizable styling
Slider uses a native range input with min, max, step, name and disabled. It supports three sizes, controlled or uncontrolled values, and an optional formatted value label. Use it for selecting a number from a range; Input is better when an exact value needs to be typed.
Browser Support
Colors the hover halo around the thumb.
Preview
Drag the slider to change the value.
Installation
Usage
import { Slider } from "@/components/ui/slider"
export default function Example() {
const [value, setValue] = useState(50)
return (
<Slider
value={value}
onValueChange={setValue}
min={0}
max={100}
/>
)
}Examples
With Value Display
Show the current value next to the slider with custom formatting.
<Slider
value={value}
onValueChange={setValue}
showValue
formatValue={(v) => `${v}%`}
/>Animated Sliding Value
Use animateValue for smooth digit transitions powered by SlidingNumber.
<Slider
value={value}
onValueChange={setValue}
showValue
animateValue
formatValue={(v) => `${v}%`}
/>Size Variants
Three size variants: small, medium (default), and large.
<Slider size="sm" defaultValue={30} />
<Slider size="md" defaultValue={50} />
<Slider size="lg" defaultValue={70} />Step Increments
Control the step size for discrete value selection.
Step: 10 (values: 0, 10, 20, ... 100)
<Slider
min={0}
max={100}
step={10}
showValue
/>Custom Formatting
Use formatValue to display units like temperature or currency.
<Slider
min={16}
max={30}
showValue
formatValue={(v) => `${v}°C`}
/>
<Slider
min={0}
max={500}
step={10}
showValue
formatValue={(v) => `$${v}`}
/>Custom Gradient Track
Set the --slider-track, --slider-fill and --slider-thumb CSS variables on the wrapper to restyle the slider.
Custom gradient track using CSS overrides
/* Any background works for the track */
.gradient-slider {
--slider-track: linear-gradient(
to right,
var(--chart-1),
var(--chart-2),
var(--chart-3),
var(--chart-4),
var(--chart-5)
);
--slider-fill: transparent;
}
<Slider className="gradient-slider" />Disabled State
Disabled slider with reduced opacity and non-interactive state.
<Slider defaultValue={40} disabled />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | - | Controlled value |
| defaultValue | number | 50 | Default value for uncontrolled mode |
| min | number | 0 | Minimum value |
| max | number | 100 | Maximum value |
| step | number | 1 | Step increment |
| onValueChange | (value: number) => void | - | Callback when value changes |
| showValue | boolean | false | Show value label next to slider |
| animateValue | boolean | false | Animate value with sliding digits (requires showValue) |
| formatValue | (value: number) => string | String(v) | Custom value formatter |
| size | "sm" | "md" | "lg" | "md" | Slider size |
| disabled | boolean | false | Disabled state |
| label | string | - | Accessible label for screen readers (aria-label) |
| name | string | - | Field name, so the value goes to FormData |
| className | string | - | Additional CSS classes |
Features
- Pure CSS — no external animation or UI libraries required
- Cross-browser — works in Chrome, Firefox, Safari, Edge via vendor prefixes
- Progress fill — CSS only: border-image on the thumb in WebKit, ::-moz-range-progress in Firefox
- Keyboard accessible — full arrow key and focus support
- ARIA attributes — aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext
- Customizable — size variants, custom formatting, gradient tracks
- Animated values — optional SlidingNumber integration for smooth digit transitions
- Controlled & uncontrolled — works with value/onValueChange or defaultValue