Skip to main content

Slider

An input where the user selects a value from within a given range. Pass aria-label to Slider, also inside a Field, so the thumb has an accessible name.

When to use

  • Pick a number, or a range between two numbers, with a thumb that moves along a track.
  • Pair it with Field to connect a description and errors in a form.
  • Prefer Input when the user types an exact number.

Disabled

Set disabled to stop the user from changing the value.

Vertical

Set orientation="vertical" to draw the track vertically.

Examples

With TanStack Form

Use @tanstack/react-form with zod to keep a single-thumb slider controlled. Radix emits slider values as an array, so pass the first value into field.handleChange.

Single thumb

A basic slider with a single thumb for selecting a single value. You can pass a single number instead of an array.

Range

Use two values to create a range slider with two thumbs.

Multiple thumbs

Use more than two values to create a slider with multiple thumbs.

Color

Use the color prop to change the color of the slider range. Accepts any Tailwind bg-* class.

Ticks

Use the showTicks prop to show tick marks along the track, one per step, spread evenly. When the range is not a multiple of step, the ticks do not land on the step values.

API Reference

Slider

The Slider is built on top of Radix Slider. It accepts all props from the Radix Slider Root component.

defaultValue and value both accept number | number[], but they must be the same type. You cannot mix a single number with a number[].

PropTypeDefaultDescription
color`bg-${string}`"bg-accent-600"The color of the slider range. Accepts any Tailwind bg-* class.
aria-labelstringAccessible name forwarded to the rendered thumb. Range sliders derive per-thumb labels from it.
aria-labelledbystringIDREF forwarded to every thumb, so a range slider names both thumbs with the same text. Prefer aria-label.
defaultValuenumber | number[]The value of the slider when initially rendered. Use when you do not need to control the state of the slider.
showTicksbooleanfalseWhether to show tick marks along the track, one per step, spread evenly.
valuenumber | number[]The controlled value of the slider. Must be used with onValueChange.
onValueChange(value: number[]) => voidEvent handler called when the value changes.
onValueCommit(value: number[]) => voidEvent handler called when the value changes at the end of an interaction (e.g. on mouse up or on blur).
namestringThe name of the slider. Submitted with its owning form as part of a name/value pair.
disabledbooleanfalseWhen true, prevents the user from interacting with the slider.
orientation"horizontal" | "vertical""horizontal"The orientation of the slider.
minnumber0The minimum value for the range.
maxnumber100The maximum value for the range.
stepnumber1The stepping interval.
minStepsBetweenThumbsnumber1The minimum permitted steps between multiple thumbs.
invertedbooleanfalseWhether the slider is visually inverted.