---
title: "Slider"
description: "A range control with a filled track, a grabber and optional labelled marks, for volumes and thresholds."
---

A slider is for a value the reader feels their way to, such as a volume or a sensitivity threshold. When the exact number matters more than its position on a scale, use a [Number Input](/docs/components/number-input) instead.

It is built on [Radix Slider](https://www.radix-ui.com/primitives/docs/components/slider) in React and [Reka UI Slider](https://reka-ui.com/docs/components/slider) in Vue. The primitive owns the pointer, the keyboard and the announced value. The value is an array with one number per grabber, so `[40]` draws one grabber and `[20, 80]` draws two.

_Live example of Slider — see the page for the rendered demo._

## Installation

```bash
npx newtui@latest add slider
```

npm dependencies: React: radix-ui. Vue: reka-ui.

Files written — React: components/ui/slider.tsx. Vue: components/ui/slider/Slider.vue, components/ui/slider/index.ts.

## Usage

React:

```tsx
import { Slider } from "@/components/ui/slider"
```

Vue:

```ts
import { Slider } from "@/components/ui/slider"
```

## Examples

### Named steps

With a small `max` and a mark at every stop, the slider becomes a short scale of named levels. Pass `aria-valuetext` so a screen reader hears the name and not the number.

_Live example of Slider — see the page for the rendered demo._

### Custom range

`min`, `max` and `step` set the scale: this one runs from 8 to 96 in steps of 8. Without `marks` the track is drawn alone, so show the current value beside it.

_Live example of Slider — see the page for the rendered demo._

### Minimum and maximum

Pass two values to get two grabbers, one for each end of a span. The `aria-label` names the group around them, and each grabber is read as "Minimum" or "Maximum". `minStepsBetweenThumbs` (`min-steps-between-thumbs` in Vue) keeps them at least one step apart.

_Live example of Slider — see the page for the rendered demo._

### Disabled

`disabled` dims the whole control and takes it out of the tab order. Say why nearby, because the slider itself cannot.

_Live example of Slider — see the page for the rendered demo._

## API reference

**`Slider`**

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value / v-model` | `number[]` | — | The current value, one number per grabber. In React, leave it undefined and pass `defaultValue` to let the slider own it. |
| `defaultValue` | `number[]` | `[min]` | The value on first render, for an uncontrolled slider. |
| `onValueChange` | `(value: number[]) => void` | — | React only. Called on every change; Vue emits `update:modelValue`. |
| `onValueCommit` | `(value: number[]) => void` | — | React only. Called when a drag or a key press ends; Vue emits `valueCommit`. |
| `min` | `number` | `0` | The low end of the range. |
| `max` | `number` | `100` | The high end of the range. |
| `step` | `number` | `1` | The distance between two values. |
| `minStepsBetweenThumbs` | `number` | `0` | The smallest gap, in steps, between two grabbers. |
| `marks` | `{ value: number; label?: string }[]` | — | Labelled points drawn above the track. A mark without a label shows its number. |
| `name` | `string` | — | The field name. Inside a `<form>`, the slider submits its value under this name. |
| `dir` | `"ltr" \| "rtl"` | `"ltr"` | The direction the value grows in. Set it to `rtl` in a right-to-left layout. |
| `disabled` | `boolean` | `false` | Dims the control and stops it taking input. |

`Slider` accepts every other prop of the primitive root, such as `inverted`. Other attributes go to the slider root. `className` (React) or `class` (Vue) goes to the wrapper around the marks and the track.

## Accessibility

Each grabber has `role="slider"` and takes keyboard focus. The arrow keys move it by one step. `Page Up`, `Page Down` and `Shift` with an arrow key move it by ten steps. `Home` and `End` go to the ends of the range.

Give the slider a name with `aria-label` or `aria-labelledby`. With one grabber, the name and `aria-valuetext` go to that grabber. With two grabbers, the name goes to a `role="group"` around them, and the grabbers are named "Minimum" and "Maximum". The marks are decoration and are hidden from assistive technology. A grabber shows a 2px `--newt-text-link` outline while it has keyboard focus.

## Tokens

Slider reads its colours, radii and motion from the `--newt-*` tokens. Override a token rather than editing the component.
