Picks a range with two thumbs. Under the hood there are two native range inputs stacked on top of each other, so keyboard, touch and screen readers work the way the browser already handles them. The fill between the thumbs is pure CSS: each thumb paints a band with border-image, so the slider looks right and submits its values before hydration. A few lines of client code keep the thumbs from crossing, update the value labels and call onValueChange. An edge value can be reported as null, meaning no limit.
Browser Support
Groups related styles
Colors the slider focus ring
Preview
Drag the thumbs or focus one and use the arrow keys.
[20, 80]
Installation
Usage
import { RangeSlider } from "@/components/ui/range-slider"
export default function Example() {
const [value, setValue] = useState<[number, number]>([20, 80])
return <RangeSlider value={value} onValueChange={setValue} />
}Examples
With number fields and open edges
With nullableEdges a thumb resting on its edge reports null, which fits filters like price from or price up to. The fields and the slider share one state, so typing a number moves a thumb and dragging updates the field.
{ min: 250, max: null }
const [value, setValue] = useState<NullableRangeValue>([250, null])
const [from, to] = value
<RangeSlider
nullableEdges
min={0}
max={2000}
step={50}
minGap={100}
value={value}
onValueChange={setValue}
showValues={false}
/>
<Input
type="number"
placeholder="0"
value={from ?? ""}
onChange={(e) => setValue([e.target.value ? Number(e.target.value) : null, to])}
/>
<Input
type="number"
placeholder="2000"
value={to ?? ""}
onChange={(e) => setValue([from, e.target.value ? Number(e.target.value) : null])}
/>Formatted values
formatValue changes the labels under the track and the aria-valuetext that screen readers announce. Here minGap keeps the range at least two hours long.
<RangeSlider
min={0}
max={24}
minGap={2}
defaultValue={[9, 18]}
formatValue={(v) => `${String(v).padStart(2, "0")}:00`}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | RangeValue | NullableRangeValue | - | Current range in controlled mode |
| defaultValue | RangeValue | NullableRangeValue | [min, max] | Initial range in uncontrolled mode |
| onValueChange | (value) => void | - | Called with the new range on every move |
| min | number | 0 | Lowest value |
| max | number | 100 | Highest value |
| step | number | 1 | Step of both thumbs |
| minGap | number | 0 | Smallest allowed distance between the thumbs |
| nullableEdges | boolean | false | Report a thumb on its edge as null |
| formatValue | (value: number) => string | String | Formats value labels and aria-valuetext |
| showValues | boolean | true | Show formatted values under the track |
| name | string | - | Form field prefix: inputs get name-min and name-max |
| disabled | boolean | false | Turns off interaction |
| labels | { min?: string; max?: string } | - | Accessible names of the lower and upper thumb |
| className | string | - | Additional CSS classes |
Features
- Native inputs: arrow keys, Page Up and Page Down, Home and End work without extra code
- No crossing: each thumb stops at the other one plus minGap. The upper thumb is always on top, so when both sit at the end, drag the upper one first
- CSS fill: the thumbs paint the fill themselves, no width math in JavaScript and no jump on hydration