Design System
Forms

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:

Controlled with a live readout
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

PropertyValue
Track6px tall (h-1.5), full width, --secondary, pill radius
Fill--primary, from the start (or between two thumbs)
Thumb16px circle (size-4), 2px --primary border, --background fill, --shadow-1
Focus2px --ring with 2px offset on the thumb
Disabled50% opacity, no pointer events
Defaultsmin 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 step that matches how the value is used; 5% steps beat 1% when the backend rounds anyway.
  • Name each thumb with thumbLabels when 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" with aria-valuemin/aria-valuemax/aria-valuenow managed by Radix.
  • Every thumb gets an aria-label from thumbLabels — WCAG requires role="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.
  • id lands on the first thumb — the focusable role="slider" element — so Label htmlFor is a real programmatic pairing and clicking the label focuses the handle. For a range, the label names the first thumb; thumbLabels still 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 to min/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:

PropTypeDefaultDescription
idstring | 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.
valuenumber[] | undefined—Controlled value(s), one entry per thumb — e.g. `[50]` for a single handle, `[25, 75]` for a range.
defaultValuenumber[] | undefined[0]Uncontrolled starting value(s), one entry per thumb; the number of entries also determines how many thumbs render.
thumbLabelsstring[] | 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"]`.
minnumber | undefined——
maxnumber | undefined——
invertedboolean | undefined——
formstring | undefined——
dirDirection | undefined——
asChildboolean | undefined——
namestring | undefined——
disabledboolean | undefined——
orientation"horizontal" | "vertical" | undefined——
stepnumber | undefined——
minStepsBetweenThumbsnumber | undefined——
onValueChange((value: number[]) => void) | undefined——
onValueCommit((value: number[]) => void) | undefined——

On this page