# Slider

> A value on a continuous track; pass two values for a range.

Category: Selection · Atomic level: atom · Built on Base UI Slider
Page: https://ui.dtheo.dev/docs/components/slider

## Install

```bash
npx dtheo@latest add slider
# or, with the shadcn CLI
npx shadcn@latest add https://ui.dtheo.dev/r/slider.json
```

Dependencies: @base-ui/react, clsx, tailwind-merge. Registry dependencies: utils.

## Exports

`Slider`

## Use it for

- Approximate values where the position matters more than the number (a threshold, a window)

## Reach for something else

- Exact values: use Number field, or pair the slider with one

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `defaultValue` | `number \| number[]` | – | Pass two values for a range with two thumbs. |
| `thumbLabels` | `string[]` | – | A name per thumb ("Window start", "Window end") so a range is announced apart. |

## Keyboard

| Keys | Action |
| --- | --- |
| Arrow keys | Step the value |
| Page up / down | Large steps |
| Home / End | Minimum / maximum |

## Examples

### slider

```tsx
import * as React from 'react';
import { Field, FieldDescription, FieldLabel } from '@/components/ui/field';
import { Slider } from '@/components/ui/slider';

const PEAK_OVERSHOOT = 17.6;

export default function SliderExample() {
  const [threshold, setThreshold] = React.useState(15);
  const [range, setRange] = React.useState<readonly number[]>([120, 680]);
  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <div className="flex items-baseline justify-between gap-3">
          <FieldLabel>Overshoot warning</FieldLabel>
          <span className="text-label text-muted-foreground tabular-nums">{threshold} %</span>
        </div>
        <Slider
          value={threshold}
          onValueChange={(v) => setThreshold(v as number)}
          min={0}
          max={40}
          step={1}
        />
        <FieldDescription>
          R-0412 peaked at {PEAK_OVERSHOOT} %:{' '}
          {PEAK_OVERSHOOT > threshold ? 'flagged for review.' : 'within the limit.'}
        </FieldDescription>
      </Field>
      <Field>
        <div className="flex items-baseline justify-between gap-3">
          <FieldLabel>Analysis window</FieldLabel>
          <span className="text-label text-muted-foreground tabular-nums">
            {range[0]}–{range[1]} ms
          </span>
        </div>
        <Slider
          value={range}
          onValueChange={(v) => setRange(v as readonly number[])}
          min={0}
          max={2500}
          step={10}
          minStepsBetweenValues={5}
        />
        <FieldDescription>Settling time and overshoot are computed inside this window.</FieldDescription>
      </Field>
    </div>
  );
}
```

## Used in

- Motor map (page): https://ui.dtheo.dev/examples/motor-map
