# Slider

An input where the user selects a value from within a given range.

Page: https://sui.draco.dev/docs/components/slider

### Example: slider-demo

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

export function SliderDemo() {
  return (
    <Slider
      defaultValue={[75]}
      max={100}
      step={1}
      className="mx-auto w-full max-w-xs"
    />
  );
}

export default SliderDemo;
```

## Installation

```bash
bunx --bun shadcn@latest add @sui/slider
```

Install with the shadcn CLI or use the shared `@workspace/ui` package. Follow the [installation guide](/docs/installation) to configure the registry, load styles, and choose import aliases.

## Usage

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

```tsx
<Slider defaultValue={[33]} max={100} step={1} />
```

## Range

Use an array with two values for a range slider.

### Example: slider-range

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

export function SliderRange() {
  return (
    <Slider
      defaultValue={[25, 50]}
      max={100}
      step={5}
      className="mx-auto w-full max-w-xs"
    />
  );
}

export default SliderRange;
```

## Multiple Thumbs

Use an array with multiple values for multiple thumbs.

### Example: slider-multiple

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

export function SliderMultiple() {
  return (
    <Slider
      defaultValue={[10, 20, 70]}
      max={100}
      step={10}
      className="mx-auto w-full max-w-xs"
    />
  );
}

export default SliderMultiple;
```

## Vertical

Use `orientation="vertical"` for a vertical slider.

### Example: slider-vertical

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

export function SliderVertical() {
  return (
    <div className="mx-auto flex w-full max-w-xs items-center justify-center gap-6">
      <Slider
        defaultValue={[50]}
        max={100}
        step={1}
        orientation="vertical"
        className="h-40"
      />
      <Slider
        defaultValue={[25]}
        max={100}
        step={1}
        orientation="vertical"
        className="h-40"
      />
    </div>
  );
}

export default SliderVertical;
```

## Controlled

### Example: slider-controlled

```tsx
"use client";

import { Label } from "@workspace/ui/components/label";
import { Slider } from "@workspace/ui/components/slider";
import * as React from "react";
import { useId as usePreviewId } from "react";

export function SliderControlled() {
  const previewId = usePreviewId();

  const [value, setValue] = React.useState([0.3, 0.7]);

  return (
    <div className="mx-auto grid w-full max-w-xs gap-3">
      <div className="flex items-center justify-between gap-2">
        <Label htmlFor={`${previewId}-slider-demo-temperature`}>
          Temperature
        </Label>
        <span className="text-muted-foreground text-sm">
          {value.join(", ")}
        </span>
      </div>
      <Slider
        id={`${previewId}-slider-demo-temperature`}
        value={value}
        onValueChange={(value) => setValue(value as number[])}
        min={0}
        max={1}
        step={0.1}
      />
    </div>
  );
}

export default SliderControlled;
```

## Disabled

Use the `disabled` prop to disable the slider.

### Example: slider-disabled

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

export function SliderDisabled() {
  return (
    <Slider
      defaultValue={[50]}
      max={100}
      step={1}
      disabled
      className="mx-auto w-full max-w-xs"
    />
  );
}

export default SliderDisabled;
```

## RTL

To enable RTL support in shadcn/ui, see the [RTL configuration guide](https://ui.shadcn.com/docs/rtl).

### Example: slider-rtl

```tsx
"use client";

import { Slider } from "@workspace/ui/components/slider";
import { type Translations, useTranslation } from "./support";

const translations: Translations = {
  en: {
    dir: "ltr",
    values: {},
  },
  ar: {
    dir: "rtl",
    values: {},
  },
  he: {
    dir: "rtl",
    values: {},
  },
};

export function SliderRtl() {
  const { dir } = useTranslation(translations, "ar");

  return (
    <Slider
      defaultValue={[75]}
      max={100}
      step={1}
      className="mx-auto w-full max-w-xs"
      dir={dir}
    />
  );
}

export default SliderRtl;
```

## API Reference

See the [Base UI Slider](https://base-ui.com/react/components/slider#api-reference) documentation.

- [Documentation](https://base-ui.com/react/components/slider)
- [API reference](https://base-ui.com/react/components/slider#api-reference)
