---
title: "Slider"
description: "A single coarse, non-clinical preference set by dragging a thumb along a track, and never a clinical reading or a precise measurement."
url: "https://opsinjs.pensievelabs.org/docs/components/slider"
source: "https://opsinjs.pensievelabs.org/docs/components/slider.md"
section: "Components"
status: "shipped"
kind: "component"
category: "actions-and-forms"
reviewed: "2026-09-20"
reviewer: "engineering"
aliases: ["range input", "drag to set"]
implemented: true
---

> Elements written as `<PascalCase … />` below are opsinjs documentation
> components. Their attributes are the content: the values they render are
> generated from `tokens/*.json` and `registry/catalogue.ts` and are
> published separately at https://opsinjs.pensievelabs.org/r/index.json and under the Reference
> section.
> `<StubNotice>` IS THE EXCEPTION, AND IT IS THE ONE TO READ. It is a
> paired element rather than a self-closing one, and the text between
> its opening and closing tags is prose an author wrote, reproduced
> below word for word. That prose is where this page says whether the
> component has been reviewed. Read the children, not only the
> attributes.

<StubNotice
  name="slider"
  status="shipped"
  questions="[
  &#x22;No contrast pair has been measured: the knob against the accent fill and the muted track, and the focus ring against all three.&#x22;,
  &#x22;Nobody has heard this in a screen reader, and the thumb carries no aria-valuetext, so it speaks a raw number rather than a described position.&#x22;,
  &#x22;Forced colours and prefers-contrast: more are unhandled, and whether the thumb still reads as a distinct object on the track is untested.&#x22;,
]"
>
  Audited against WCAG 2.2 AA. Clinical review pending.
</StubNotice>

## Usage [#usage]

<ComponentInstall name="slider" unbuilt="false" importPath="@/components/ui/slider" dependencies="[&#x22;@base-ui/react&#x22;]" />

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

```tsx
<Slider
  label="Screen brightness"
  value={brightness}
  onValueChange={setBrightness}
/>
```

## Examples [#examples]

<ComponentPreview name="slider" />

### A coarse preference [#a-coarse-preference]

A fictional notification volume from nought to a hundred, driven by `value` and
`onValueChange`.

<ComponentPreview name="slider-a-coarse-preference" kind="example" align="start" />

### With steps [#with-steps]

`min`, `max` and `step` snap the thumb to stops: a fictional map zoom running
from one to nine in twos.

<ComponentPreview name="slider-with-steps" kind="example" align="start" />

## When to use it [#when-to-use-it]

<WhenToUse
  use="[
  &#x22;A coarse, non-clinical preference such as a brightness level, where the exact number does not matter.&#x22;,
  &#x22;A value adjusted by feel, where sliding towards more or less beats typing a figure.&#x22;,
  &#x22;A setting with a small set of stops the reader can actually mean.&#x22;,
]"
  avoid="[
  { case: &#x22;You are capturing a clinical reading. A slider turns a value the person meant into a value the pixel chose.&#x22;, instead: &#x22;reading-input&#x22; },
  { case: &#x22;You need a precise non-clinical quantity where the digits matter.&#x22;, instead: &#x22;number-field&#x22; },
  { case: &#x22;The reader picks one of a small set of named options rather than a point on a continuum.&#x22;, instead: &#x22;segmented-control&#x22; },
]"
/>

## Accessibility [#accessibility]

The audit found no axe violation, target-size breach or reflow failure, and
changed nothing. The thumb wraps Base UI unmodified, so click-to-position plus
Arrow, Home, End and Page keys give every drag a keyboard alternative (SC 2.5.7
Dragging). The role, `aria-valuenow`, `min` and `max` come from the nested real
range input, and the `Slider.Label` text is forwarded onto it so the name is
present at render (SC 4.1.2 Name, Role, Value). The thumb hit area is floored at
`--opsin-target-minimum` on both axes, with the knob drawn smaller inside (SC
2.5.8).

**Residual items.**

* The knob's colour fade on interaction has no reduced-motion guard, but it is a colour change and not positional motion, so any neutralisation belongs in a shared stylesheet.
* The `Slider.Value` readout renders as an `output` with a polite live region, so while dragging the value is spoken twice, a verbosity and not a defect.
* Contrast pairs remain unmeasured.

<KeyboardTable
  name="slider"
  rows="[
  {
    keys: &#x22;Tab&#x22;,
    action: &#x22;Moves focus onto the thumb&#x22;,
    notes: &#x22;One tab stop, on the thumb's nested range input.&#x22;,
  },
  {
    keys: &#x22;Shift + Tab&#x22;,
    action: &#x22;Moves focus back out of the control&#x22;,
    notes: &#x22;A single stop in reverse too.&#x22;,
  },
  {
    keys: &#x22;Arrow Right, Arrow Up&#x22;,
    action: &#x22;Increases the value by one step&#x22;,
    notes: &#x22;The `step` prop. A right-to-left layout swaps Left and Right.&#x22;,
  },
  {
    keys: &#x22;Arrow Left, Arrow Down&#x22;,
    action: &#x22;Decreases the value by one step&#x22;,
    notes: &#x22;The `step` prop, and the value stops at `min`.&#x22;,
  },
  {
    keys: &#x22;Home&#x22;,
    action: &#x22;Sets the value to the minimum&#x22;,
    notes: &#x22;Jumps the thumb to the start.&#x22;,
  },
  {
    keys: &#x22;End&#x22;,
    action: &#x22;Sets the value to the maximum&#x22;,
    notes: &#x22;Jumps the thumb to the end.&#x22;,
  },
  {
    keys: &#x22;Page Up, Page Down&#x22;,
    action: &#x22;Increases or decreases by a larger step&#x22;,
    notes: &#x22;Base UI's default of ten, not the `step` prop.&#x22;,
  },
]"
/>

<ContrastReport component="slider" />

## Props interface [#props-interface]

<PropsTable name="SliderProps" />

`value` and `onValueChange` make this controlled, so the caller holds the number.
`label` is required and a missing one raises a development warning. `min`
defaults to 0, `max` to 100 and `step` to 1.
