Slider
Choose a number from a continuous range by dragging. Best when the rough magnitude matters more than the exact figure.
Purpose
A slider trades precision for feel — dragging communicates "about this much" faster than typing,
but landing on an exact figure is fiddly. Use it for percentages, weightings and thresholds
where the neighbourhood is what matters. When the exact value matters, use an
Input with inputMode="numeric"; for small integer counts, a
Quantity toggle. Built on Radix Slider: one entry per thumb,
so [50] renders a single handle and [25, 75] a range.
Range
Two values, two thumbs — the filled bar spans between them. Radix keeps the thumbs ordered, so the minimum can never be dragged past the maximum:
With a label and readout
The slider shows position, not the number — put a visible Label beside it and echo the current
value. id lands on the first thumb, so htmlFor pairs the label with the handle; the announced
name of each thumb still comes from thumbLabels, so keep the two in step:
const [value, setValue] = React.useState([60]);
<div className="grid w-72 gap-2">
<div className="flex items-center justify-between">
<Label htmlFor="co-pay">Co-pay share</Label>
<span className="text-sm text-muted-foreground">{value[0]}%</span>
</div>
<Slider
id="co-pay"
value={value}
onValueChange={setValue}
max={100}
step={5}
thumbLabels={["Co-pay share"]}
/>
</div>States
Default, range and disabled. Focus draws a 2px --ring around the focused thumb.
Structure
| Property | Value |
|---|---|
| Track | 6px tall (h-1.5), full width, --secondary, pill radius |
| Fill | --primary, from the start (or between two thumbs) |
| Thumb | 16px circle (size-4), 2px --primary border, --background fill, --shadow-1 |
| Focus | 2px --ring with 2px offset on the thumb |
| Disabled | 50% opacity, no pointer events |
| Defaults | min 0 · max 100 · step 1 (Radix defaults) |
Best practices
Do
- Show the current value next to the label — the track alone gives no number.
- Choose a
stepthat matches how the value is used; 5% steps beat 1% when the backend rounds anyway. - Name each thumb with
thumbLabelswhen the defaults ("Value", or "Minimum"/"Maximum") do not describe the field. - Keep the track wide — precision scales with pixels per step.
Don't
- Use a slider for values users type from a document — a claim amount in MYR is an Input.
- Offer a huge range with a tiny step — hitting 4,873 of 10,000 by dragging is guesswork.
- Hide the scale — at minimum show the endpoints so the position means something.
Accessibility & keyboard
- Each thumb renders
role="slider"witharia-valuemin/aria-valuemax/aria-valuenowmanaged by Radix. - Every thumb gets an
aria-labelfromthumbLabels— WCAG requiresrole="slider"to be named, so the component falls back to "Value" for one thumb and "Minimum"/"Maximum" for two rather than announcing a bare number. Override them with something specific. idlands on the first thumb — the focusablerole="slider"element — soLabel htmlForis a real programmatic pairing and clicking the label focuses the handle. For a range, the label names the first thumb;thumbLabelsstill names each thumb individually.- Interaction is pointer- and keyboard-equivalent; the control is
touch-none, so dragging does not scroll the page on touch devices. - Keyboard: Tab moves between thumbs; Arrow keys move the focused thumb by
step(Left/Down decrease, Right/Up increase); PageUp/PageDown move in larger jumps; Home/End jump tomin/max— all Radix Slider defaults.
Props
SliderProps extends the Radix Slider root, so min, max, step, disabled,
orientation, onValueChange and onValueCommit all pass through — see the
Storybook prop tables for the
full generated API. The additions:
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined | — | Lands on the FIRST thumb, not the root: the thumb is the focusable `role="slider"` element, so this is what makes `<Label htmlFor>` a real programmatic pairing (and label clicks focus the handle). For a range, the label names the first thumb; `thumbLabels` still names each. |
value | number[] | undefined | — | Controlled value(s), one entry per thumb — e.g. `[50]` for a single handle, `[25, 75]` for a range. |
defaultValue | number[] | undefined | [0] | Uncontrolled starting value(s), one entry per thumb; the number of entries also determines how many thumbs render. |
thumbLabels | string[] | undefined | — | Accessible name per thumb. Each thumb renders `role="slider"`, which WCAG requires to have a name — otherwise a screen reader announces a bare number. Defaults to `["Value"]` for one thumb and `["Minimum", "Maximum"]` for two. Override with something specific, e.g. `["Minimum claim", "Maximum claim"]`. |
min | number | undefined | — | — |
max | number | undefined | — | — |
inverted | boolean | undefined | — | — |
form | string | undefined | — | — |
dir | Direction | undefined | — | — |
asChild | boolean | undefined | — | — |
name | string | undefined | — | — |
disabled | boolean | undefined | — | — |
orientation | "horizontal" | "vertical" | undefined | — | — |
step | number | undefined | — | — |
minStepsBetweenThumbs | number | undefined | — | — |
onValueChange | ((value: number[]) => void) | undefined | — | — |
onValueCommit | ((value: number[]) => void) | undefined | — | — |