# Slider

A draggable control for selecting one value or a range along a track.

- Category: Core Elements
- Page: https://wunderui.com/components/slider
- Tier: Free

## Install

```bash
npx wunderui-cli add slider
```

## Import

```tsx
import { Slider, SliderBubble, SliderBubbleProps, SliderControl, SliderField, SliderFieldProps, SliderHandle, SliderIndicator, SliderInput, SliderInputProps, SliderLabel, SliderMark, SliderMarkInput, SliderMarks, SliderMarksProps, SliderProps, SliderRangeInputs, SliderRangeInputsProps, SliderThumb, SliderTrack, SliderValue } from "@/components/ui/slider"
```

## Minimal usage

Then use it:

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

export function Volume() {
  return <SliderField label="Volume" unit="%" defaultValue={40} className="w-80" />
}
```

Expected result: You see the label Volume on the left and 40% on the right, above a track filled up to 40 % and a round thumb you can drag or move with arrow keys.

## Usage

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

export function Example() {
  return (
    <SliderField
      label="Volume"
      unit="%"
      defaultValue={40}
      className="w-80 max-w-full"
    />
  )
}
```

## When to use

### Use Slider for

- Choosing a value where the rough position matters more than the exact number, such as volume, opacity or zoom
- Choosing a range between two values, such as a price or an amount
- A value on a scale around a middle point, such as a balance from -100 to +100

### Use something else

- [Number Field](https://wunderui.com/components/number-field) for an exact figure that people type or step with buttons
- [Radio Group](https://wunderui.com/components/radio-group) for a choice between a few named options, such as Day, Week and Month
- [Progress](https://wunderui.com/components/progress) for showing how far a task has come, where people cannot change the value

## Keyboard

Every thumb is a native range input, so the browser handles focus and arrow keys, and the slider adds larger steps. A range has two tab stops, the lower thumb first.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the next or previous thumb. A disabled slider is skipped. |
| `ArrowRight` or `ArrowUp` | Raises the value by one `step`. |
| `ArrowLeft` or `ArrowDown` | Lowers the value by one `step`. |
| `Shift+Arrow` | Moves the value by `largeStep`, ten steps by default. |
| `PageUp` or `PageDown` | Raises or lowers the value by `largeStep`. |
| `Home` or `End` | Jumps to the minimum or to the maximum. In a range the thumb stops at the other thumb. |

## Behavior

What the slider does with its value, thumbs, states and motion.

- **Controlled or not:** Pass a value and a change handler to control it, or a default value to let it keep its own. A commit handler runs once on release or key press, which is the place to save.
- **One thumb or two:** A number gives one thumb that fills from the minimum, and an array of two gives a range where the lower thumb never passes the upper one. A click on the track moves the nearest thumb.
- **Centred:** Centred draws the fill from the middle of the scale, or from a number you pass, and marks the zero point with a short line. It works for one thumb only, and a range keeps its normal fill.
- **Vertical:** A vertical slider fills the height of its container, with the maximum at the top and the bubble beside the thumb. SliderField draws no error text for it, though the slider is still marked invalid.
- **Bubble:** The bubble fades in while the thumb has focus or is dragged, or always if set. Range thumbs closer than 15 % of the scale share one bubble, and screen readers get the value from the value text.
- **Marks and limits:** Marks are decorative ticks under the track, and only the step snaps the thumb. Limits show the lowest and highest value under the ends.
- **Value text:** A format function sets the text of the value, bubble and screen reader value, so $25 is announced as $25 and not as 25. Without it values use the English number format, such as 1,200.5.
- **Disabled:** A disabled slider is drawn at 40 % opacity, is not focusable and ignores the pointer. The value stays readable.
- **Invalid:** Invalid or an error turns the fill and thumb red and marks the thumbs invalid. The error text is an alert and describes the thumbs.
- **Hover and dragging:** The thumb fills with the page tone on hover and the subtle tone while dragged, and the cursor becomes a grab hand. The thumb follows the pointer directly, without trailing.
- **Motion:** The thumb changes its fill with a quick colour transition, and the bubble moves 4 px and fades in and out. Only opacity and transform animate.
- **Reduced motion:** With reduced motion the bubble does not move, it fades in place. Nothing else moves, because the thumb follows the pointer.

## Anatomy

- `Slider`: Holds the value and draws one thumb per value: a number gives one thumb, an array of two gives a range. It offers several thumb styles, a centred fill, a value bubble, tick marks and an error state.
- `SliderLabel`: A visible name for the slider, linked to the thumbs, placed with the value in a row inside the Slider. SliderField draws its own label.
- `SliderValue`: Shows the current value or range on the right in tabular figures.
- `SliderControl`: The area that takes pointer input, a little taller than the track so it is easy to hit. Slider already renders it.
- `SliderTrack`: The grey bar the thumbs travel on, 6 px thick, horizontal or vertical. Slider already renders it.
- `SliderIndicator`: The filled part of the track up to the value, or between the two thumbs of a range. A centred slider fills from its origin.
- `SliderThumb`: The handle people drag or move with arrow keys, Home, End, Page Up and Page Down, and the element screen readers announce. It takes the page tone on hover and the subtle tone while dragging.
- `SliderBubble`: The decorative value bubble above the thumb. It fades in on focus and while dragging, and thumbs close together share one.
- `SliderMarks`: Decorative tick marks on the scale. Label only the marks that need a word, never every step.
- `SliderField`: A slider as a form field: a label that names the thumbs, the current value with its unit, optional limits, number inputs and helper or error text. An error turns the slider red.
- `SliderInput`: A number field that follows the slider, uses the English number format, and clamps and snaps when you leave it.
- `SliderRangeInputs`: Two number fields for a range. The lower value may not pass the upper one.
- `Body`
- `Error`
- `Mark`
- `Mark Label`
- `Grip`
- `Origin`
- `Center Fill`
- `Field Label`
- `Field Value`
- `Field Limits`

## Best practices

### When to use

- Use it when the rough position matters more than the exact figure: volume, a price range, a zoom level. For an exact number use a Number Field.

### Do

- Use SliderField for every slider in a form or panel, so the label and current value always sit next to the thumb. Add number inputs when exact values matter.
- Name every slider: SliderField takes a label and a bare Slider takes an aria-label. A range is announced as Budget, minimum and Budget, maximum.
- Set the step to the precision people need and keep the large step at about ten steps. Shift with an arrow key, Page Up and Page Down move by the large step.
- Pass an array such as 20 and 80 as the value for a range. The slider draws one thumb per value.
- Label only the marks that need a word, such as the first, the default and the last. A label on every tick is noise.
- Show an error through the error prop: the fill and thumb turn red and the text is announced. Say what to change, like Choose at least 10%.
- When a slider is disabled, give the reason in the helper text. The value stays readable, and people shouldn't have to guess why they can't change it.

### Don't

- Don't add SliderThumb children for a range. The array decides how many thumbs there are.
- Don't rely on colour alone for an error. The red fill comes with the error text and an invalid state for screen readers.
- Don't use a vertical slider without a height. It fills its container's height, so a column without one gives the track nothing to stretch to.
- Don't use a Slider for a choice between a few named options. Use a Segmented Control or a Radio Group.

## API reference

### Slider

| Prop | Type | Default | Description |
|---|---|---|---|
| bubble | boolean \| "always" |  | Shows the value in a bubble above the thumb (beside it when vertical) while it has focus or is dragged. `"always"` keeps it on screen. Close range thumbs share one bubble. |
| centered | boolean \| number |  | Fills from the middle of the scale instead of the start and marks the zero point. `true` uses the middle of `min` and `max`, a number sets the origin, such as `centered={0}` on -50 to 50. A single value only. |
| className | string \| ((state: State) => string \| undefined) |  | Extra classes for the element. A function receives the state and returns the classes. |
| defaultValue | Value |  | The starting value of an uncontrolled slider: a number for one thumb, an array of two numbers for a range such as `[25, 75]`. |
| disabled | boolean | false | Dims the slider to 40 % and takes it out of the tab order and out of pointer input. The value stays readable. |
| error | React.ReactNode |  | Error text under the slider. It is announced, linked to every thumb through `aria-describedby` and marks the slider invalid. For a vertical slider the text is not drawn; use `SliderField`. |
| form | string |  | The id of the form the slider belongs to, when it is not inside that form in the markup. |
| format | Intl.NumberFormatOptions |  | `Intl.NumberFormat` options for the number shown in the bubble and in `aria-valuetext`, such as `{ style: "currency", currency: "USD" }`. `formatValue` wins when both are set. |
| formatValue | (value: number) => string |  | Turns a value into the text shown in the bubble, beside the label and in `aria-valuetext`, such as `(n) => "$" + n`. The default is the English number format. |
| handle | "circle" \| "circle-neutral" \| "grip-bars" \| "grip-dots" |  | The shape of the thumb: `circle` is the brand-outlined default, `circle-neutral` has a grey rim like a plain button, `grip-bars` and `grip-dots` are a rounded drag item. |
| invalid | boolean |  | Marks the slider invalid: the fill and the thumb turn red and the thumbs get `aria-invalid`. |
| largeStep | number | 10 | How far a value moves with Page Up, Page Down or Shift with an arrow key. The default is 10. |
| locale | Intl.LocalesArgument |  | The locale for number formatting. The default is `en-US`, so 1200.5 reads as 1,200.5. |
| marks | readonly SliderMarkInput[] |  | Tick marks under the track. A number is a tick, `{ value, label }` also names it. Label only the ticks that need a word. The marks are decorative. |
| max | number | 100 | The highest value on the scale. The default is 100. |
| min | number | 0 | The lowest value on the scale. The default is 0. |
| minStepsBetweenValues | number | 0 | For a range, the fewest steps that must stay between two thumbs, so they can never touch. The default is 0. |
| name | string |  | The name the value is submitted under when the slider is inside a form. |
| onValueChange | ((value: Value extends number ? number : Value, eventDetails: SliderRoot.ChangeEventDetails) => void) |  | Called on every change while the thumb moves, with the new value (a number for one thumb, an array for a range) and the event details. |
| onValueCommitted | ((value: Value extends number ? number : Value, eventDetails: SliderRoot.CommitEventDetails) => void) |  | Called once when a change ends: the pointer is released or a key is pressed. Use it to save instead of saving on every move. |
| orientation | "horizontal" \| "vertical" | "horizontal" | `horizontal` runs across the container and is the default. `vertical` runs up a column that has a height, with the maximum at the top. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Replaces the element with another element or component, or composes it with one. It takes an element or a function that returns one. |
| step | number | 1 | How far a value moves with one arrow key press, and the grid the thumb snaps to while dragging. The default is 1. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Inline styles for the element. A function receives the state and returns the styles. |
| thumbAlignment | 'center' \| 'edge' \| 'edge-client-only' | 'center' | How the thumb sits at the ends of the track: `center` puts its middle on the end of the track, `edge` keeps the whole thumb inside it. The default is `center`. |
| thumbClassName | string |  | Extra classes for every thumb, for example to change its fill. |
| thumbCollisionBehavior | 'push' \| 'swap' \| 'none' | 'push' | What two thumbs do when they meet: `push` moves the other thumb along, `swap` lets them trade places, `none` stops the dragged thumb at the other. The default is `push`. |
| value | Value |  | The value of a controlled slider: a number for one thumb, an array of numbers for a range. Pair it with `onValueChange`. |

Also accepts React.HTMLAttributes attributes.

### SliderBubble

| Prop | Type | Default | Description |
|---|---|---|---|
| joined | boolean |  | One bubble for two close range thumbs: place it with `style` (`left` or `bottom` in %). |
| orientation | "horizontal" \| "vertical" | "horizontal" | `horizontal` puts the bubble above the thumb, `vertical` beside it. |
| visible | boolean |  | Shows the bubble. While the slider is dragged it shows regardless. |

Also accepts React.HTMLAttributes attributes.

### SliderControl

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | Extra classes for the element. A function receives the state and returns the classes. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Replaces the element with another element or component, or composes it with one. It takes an element or a function that returns one. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Inline styles for the element. A function receives the state and returns the styles. |

Also accepts React.HTMLAttributes attributes.

### SliderField

| Prop | Type | Default | Description |
|---|---|---|---|
| label* | React.ReactNode |  | The visible name of the field. It names every thumb (`aria-labelledby`). Without a label, use `Slider` with an `aria-label`. |
| bubble | boolean \| "always" |  | Shows the value in a bubble above the thumb (beside it when vertical) while it has focus or is dragged. `"always"` keeps it on screen. Close range thumbs share one bubble. |
| centered | boolean \| number |  | Fills from the middle of the scale instead of the start and marks the zero point. `true` uses the middle of `min` and `max`, a number sets the origin, such as `centered={0}` on -50 to 50. A single value only. |
| className | string \| ((state: State) => string \| undefined) |  | Extra classes for the field, which is a full-width column. |
| defaultValue | Value |  | The starting value of an uncontrolled slider: a number for one thumb, an array of two numbers for a range such as `[25, 75]`. |
| disabled | boolean | false | Dims the slider to 40 % and takes it out of the tab order and out of pointer input. The value stays readable. |
| error | React.ReactNode |  | Error text under the field. It is announced, replaces the helper, describes the thumbs and marks the slider invalid. |
| form | string |  | The id of the form the slider belongs to, when it is not inside that form in the markup. |
| format | Intl.NumberFormatOptions |  | `Intl.NumberFormat` options for the number shown in the bubble and in `aria-valuetext`, such as `{ style: "currency", currency: "USD" }`. `formatValue` wins when both are set. |
| formatValue | (value: number) => string |  | Turns a value into the text shown in the bubble, beside the label and in `aria-valuetext`, such as `(n) => "$" + n`. The default is the English number format. |
| handle | "circle" \| "circle-neutral" \| "grip-bars" \| "grip-dots" |  | The shape of the thumb: `circle` is the brand-outlined default, `circle-neutral` has a grey rim like a plain button, `grip-bars` and `grip-dots` are a rounded drag item. |
| helper | React.ReactNode |  | A hint under the field. An `error` replaces it. It describes the thumbs through `aria-describedby`. |
| inputLabel | string |  | The accessible name of the single number field. The default is the label. |
| inputLabels | readonly [string, string] |  | The names of the two range fields. The default is "Minimum" and "Maximum" followed by the label. |
| inputPrefix | string |  | Text inside the number field before the number, such as `$`. |
| inputSuffix | string |  | Text inside the number field after the number, such as `%`. |
| invalid | boolean |  | Marks the slider invalid without error text: the fill and the thumb turn red and the thumbs get `aria-invalid`. |
| largeStep | number | 10 | How far a value moves with Page Up, Page Down or Shift with an arrow key. The default is 10. |
| locale | Intl.LocalesArgument |  | The locale for number formatting. The default is `en-US`, so 1200.5 reads as 1,200.5. |
| marks | readonly SliderMarkInput[] |  | Tick marks under the track. A number is a tick, `{ value, label }` also names it. Label only the ticks that need a word. The marks are decorative. |
| max | number | 100 | The highest value on the scale. The default is 100. |
| min | number | 0 | The lowest value on the scale. The default is 0. |
| minStepsBetweenValues | number | 0 | For a range, the fewest steps that must stay between two thumbs, so they can never touch. The default is 0. |
| name | string |  | The name the value is submitted under when the slider is inside a form. |
| onValueChange | ((value: Value extends number ? number : Value, eventDetails: SliderRoot.ChangeEventDetails) => void) |  | Called on every change while the thumb moves, with the new value (a number for one thumb, an array for a range) and the event details. |
| onValueCommitted | ((value: Value extends number ? number : Value, eventDetails: SliderRoot.CommitEventDetails) => void) |  | Called once when a change ends: the pointer is released or a key is pressed. Use it to save instead of saving on every move. |
| orientation | "horizontal" \| "vertical" | 'horizontal' | `horizontal` runs across the container and is the default. `vertical` runs up a column that has a height, with the maximum at the top. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Replaces the slider element with another element or component. It takes an element or a function that returns one. |
| showInput | boolean |  | Adds a number field beside a single slider, or two under a range slider, for exact values. |
| showLimits | boolean |  | Shows the minimum and the maximum under the track. |
| showValue | boolean | true | Shows the current value beside the label. The default is true. |
| step | number | 1 | How far a value moves with one arrow key press, and the grid the thumb snaps to while dragging. The default is 1. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Inline styles for the slider. A function receives the state and returns the styles. |
| thumbAlignment | 'center' \| 'edge' \| 'edge-client-only' | 'center' | How the thumb sits at the ends of the track: `center` puts its middle on the end of the track, `edge` keeps the whole thumb inside it. The default is `center`. |
| thumbClassName | string |  | Extra classes for every thumb, for example to change its fill. |
| thumbCollisionBehavior | 'push' \| 'swap' \| 'none' | 'push' | What two thumbs do when they meet: `push` moves the other thumb along, `swap` lets them trade places, `none` stops the dragged thumb at the other. The default is `push`. |
| unit | string |  | The unit after the current value: `%` sits against the number, a word such as `px` gets a space. |
| value | Value |  | The value of a controlled slider: a number for one thumb, an array of numbers for a range. Pair it with `onValueChange`. |

Also accepts React.HTMLAttributes attributes.

### SliderIndicator

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | Extra classes for the element. A function receives the state and returns the classes. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Replaces the element with another element or component, or composes it with one. It takes an element or a function that returns one. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Inline styles for the element. A function receives the state and returns the styles. |

Also accepts React.HTMLAttributes attributes.

### SliderInput

| Prop | Type | Default | Description |
|---|---|---|---|
| label* | string |  | The accessible name of the field. It is shown above the field when `showLabel` is set. |
| onValueChange* | (value: number) => void |  | Called with a valid value that is in range, as it is typed and again when the field is left. |
| value* | number |  | The current value of the slider. |
| className | string |  | Extra classes for the wrapper of the label and the field. |
| disabled | boolean |  | Dims the field and takes it out of reach. |
| invalid | boolean |  | Draws the field in its error style. |
| max | number | 100 | The highest accepted value. A larger value is set to it when the field is left. The default is 100. |
| min | number | 0 | The lowest accepted value. A smaller value is set to it when the field is left. The default is 0. |
| prefix | string |  | Text inside the field before the number, such as `$`. |
| showLabel | boolean |  | Shows the label above the field instead of hiding it visually. |
| step | number | 1 | The grid a value snaps to when the field is left. The default is 1. |
| suffix | string |  | Text inside the field after the number, such as `%`. |
| validate | (value: number) => string \| null |  | An extra rule checked before a value is accepted. Return the error text, or null. |

### SliderLabel

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | Extra classes for the label. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Replaces the label element with another element or component. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Inline styles for the label. |

Also accepts React.HTMLAttributes attributes.

### SliderMarks

| Prop | Type | Default | Description |
|---|---|---|---|
| marks* | readonly SliderMarkInput[] |  | The ticks on the scale: a number, or `{ value, label }` to name one. Label only the ones that need a word. |
| max | number | 100 | The highest value of the scale. Give it the same `max` as the slider. |
| min | number | 0 | The lowest value of the scale. Give it the same `min` as the slider. |
| orientation | "horizontal" \| "vertical" | "horizontal" | `horizontal` puts the ticks under the track, `vertical` beside it. |

Also accepts React.HTMLAttributes attributes.

### SliderRangeInputs

| Prop | Type | Default | Description |
|---|---|---|---|
| onValueChange* | (value: [number, number]) => void |  | Called with `[lower, upper]` when either field gets a valid value. |
| value* | readonly number[] |  | The current range as two numbers. |
| className | string |  | Extra classes for the row of the two fields. |
| disabled | boolean |  | Dims both fields and takes them out of reach. |
| invalid | boolean |  | Draws both fields in their error style. |
| labels | readonly [string, string] | ["Minimum value", "Maximum value"] | The names of the two fields. The default is "Minimum value" and "Maximum value". |
| max | number |  | The highest accepted value. The default is 100. |
| min | number |  | The lowest accepted value. The default is 0. |
| prefix | string |  | Text inside each field before the number, such as `$`. |
| step | number |  | The grid a value snaps to when a field is left. The default is 1. |
| suffix | string |  | Text inside each field after the number, such as `%`. |

### SliderThumb

| Prop | Type | Default | Description |
|---|---|---|---|
| aria-valuetext | React.AriaAttributes['aria-valuetext'] |  | Text that says what the value means, such as `$25`, when the number alone is not enough for a screen reader. |
| className | string \| ((state: State) => string \| undefined) |  | Extra classes for the thumb, for example a different fill. |
| disabled | boolean | false | Disables this thumb. |
| getAriaLabel | ((index: number) => string) \| null |  | Returns the accessible name of the thumb from its index, such as `(index) => (index === 0 ? "Minimum" : "Maximum")`. |
| getAriaValueText | ((formattedValue: string, value: number, index: number) => string) \| null |  | Returns the `aria-valuetext` of the thumb from the formatted value, the raw value and the index. |
| handle | "circle" \| "circle-neutral" \| "grip-bars" \| "grip-dots" | "circle" | The shape of this thumb. See `handle` on `Slider`. |
| index | number |  | The position of the thumb in a range: 0 for the lower one, 1 for the upper one. `Slider` sets it for you. |
| inputRef | React.Ref<HTMLInputElement> |  | A ref to the hidden range input inside the thumb, the focusable element. |
| invalid | boolean |  | Puts `aria-invalid` on the range input inside the thumb. |
| onBlur | React.FocusEventHandler<HTMLInputElement> |  | Called when the range input inside the thumb loses focus. |
| onFocus | React.FocusEventHandler<HTMLInputElement> |  | Called when the range input inside the thumb gets focus. |
| onKeyDown | React.KeyboardEventHandler<HTMLInputElement> |  | Called when a key is pressed on the thumb, before the slider handles it. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Replaces the thumb element with another element or component. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Inline styles for the thumb. |
| tabIndex | number |  | The position of the thumb in the tab order. The default is 0. |

Also accepts React.HTMLAttributes attributes.

### SliderTrack

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | Extra classes for the element. A function receives the state and returns the classes. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Replaces the element with another element or component, or composes it with one. It takes an element or a function that returns one. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Inline styles for the element. A function receives the state and returns the styles. |

Also accepts React.HTMLAttributes attributes.

### SliderValue

| Prop | Type | Default | Description |
|---|---|---|---|
| children | null \| ((formattedValues: readonly string[], values: readonly number[]) => React.ReactNode) |  | A function that receives the formatted values and the raw values and returns what to show, for example `(formatted) => formatted.join(" – ")`. Without it the value is shown as formatted text. |
| className | string \| ((state: State) => string \| undefined) |  | Extra classes for the value. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Replaces the value element with another element or component. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Inline styles for the value. |

Also accepts React.OutputHTMLAttributes attributes.

## Examples

### Orientation: across a container, or up a column with a height

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

export function Example() {
  return (
    <Slider aria-label="Volume" defaultValue={40} className="w-64 max-w-full" />
  )
}
```

### Value display: beside the label, or in a bubble above the thumb

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

export function Example() {
  return (
    <SliderField
      label="Volume"
      unit="%"
      defaultValue={40}
      className="w-72 max-w-full"
    />
  )
}
```

### Scale: limits, tick marks and number inputs

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

export function Example() {
  return (
    <SliderField
      label="Opacity"
      unit="%"
      defaultValue={60}
      showLimits
      className="w-80 max-w-full"
    />
  )
}
```

### States: default, with a helper, disabled and invalid

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

export function Example() {
  return (
    <SliderField
      label="Opacity"
      unit="%"
      defaultValue={60}
      className="w-80 max-w-full"
    />
  )
}
```

## In context

### Opacity in an appearance panel: limits and a number input

Each field shows its value beside the label, its limits under the track and a number input for an exact value. The slider and the input always show the same value.

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { SliderField } from "@/components/ui/slider"

export function Example() {
  return (
    <Card className="w-96 max-w-full">
      <CardHeader>
        <CardTitle>Appearance</CardTitle>
        <CardDescription>Selected layer: Hero image</CardDescription>
      </CardHeader>
      <CardContent className="flex flex-col gap-4">
        <SliderField
          label="Opacity"
          unit="%"
          defaultValue={80}
          showLimits
          showInput
          inputSuffix="%"
        />
        <SliderField
          label="Corner radius"
          unit="px"
          max={48}
          defaultValue={12}
          showLimits
          showInput
        />
      </CardContent>
    </Card>
  )
}
```

### Price range filter: two named values and a check on the range

The range has two thumbs and two inputs. The inputs refuse a minimum above the maximum, and the field shows its own error when the range is too narrow.

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { SliderField } from "@/components/ui/slider"

export function Example() {
  return (
    <Card className="w-96 max-w-full">
      <CardHeader>
        <CardTitle>Filters</CardTitle>
        <CardDescription>Invoices</CardDescription>
      </CardHeader>
      <CardContent>
        <SliderField
          label="Amount"
          max={2000}
          step={10}
          defaultValue={[250, 1200]}
          formatValue={(n) => `$${n.toLocaleString("en-US")}`}
          showLimits
          showInput
          inputPrefix="$"
          inputLabels={["Minimum amount", "Maximum amount"]}
          helper="Invoices in your workspace currency."
        />
      </CardContent>
    </Card>
  )
}
```

### Zoom with steps: a tick for every step, a label on the main ones

Label only the steps that need a word. A tick for every step shows that the slider moves in steps, while a label on every tick would be noise.

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { SliderField } from "@/components/ui/slider"

export function Example() {
  return (
    <Card className="w-96 max-w-full">
      <CardHeader>
        <CardTitle>View</CardTitle>
        <CardDescription>Canvas</CardDescription>
      </CardHeader>
      <CardContent>
        <SliderField
          label="Zoom"
          unit="%"
          min={25}
          max={200}
          step={25}
          defaultValue={100}
          marks={[{ value: 25, label: "25%" }, 50, 75, { value: 100, label: "100%" }, 125, 150, 175, { value: 200, label: "200%" }]}
        />
      </CardContent>
    </Card>
  )
}
```

### Volume with an icon: a leading icon beside the field

The icon is decoration, so it is hidden from assistive technology. The label and the value say what the slider is.

```tsx
import { Volume2 } from "lucide-react"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { SliderField } from "@/components/ui/slider"

export function Example() {
  return (
    <Card className="w-96 max-w-full">
      <CardHeader>
        <CardTitle>Sound</CardTitle>
        <CardDescription>Output device: Studio Display</CardDescription>
      </CardHeader>
      <CardContent>
        <div className="flex items-start gap-3">
          <Volume2 aria-hidden strokeWidth={1.5} className="mt-0.5 size-5 shrink-0 text-text-secondary" />
          <SliderField label="Volume" unit="%" defaultValue={60} />
        </div>
      </CardContent>
    </Card>
  )
}
```

### Level mixer: vertical sliders with the level above each

Each slider is controlled, so the figure above it follows the thumb. Focus a thumb and use the arrow keys to change a level by one.

```tsx
import * as React from "react"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Slider } from "@/components/ui/slider"

const CHANNELS = ["Music","Voice","Effects","Master"]

export function Example() {
  const [levels, setLevels] = React.useState([70,85,40,90])
  return (
    <Card className="w-96 max-w-full">
      <CardHeader>
        <CardTitle>Mixer</CardTitle>
        <CardDescription>Channel levels</CardDescription>
      </CardHeader>
      <CardContent className="flex justify-between gap-2">
        {CHANNELS.map((name, index) => (
          <div key={name} className="flex flex-col items-center gap-3">
            <span className="text-sm tabular-nums text-text-secondary">{levels[index]}</span>
            <div className="h-40">
              <Slider
                orientation="vertical"
                aria-label={name}
                value={levels[index]}
                onValueChange={(next) => setLevels(levels.map((level, i) => (i === index ? (next as number) : level)))}
              />
            </div>
            <span className="text-sm font-medium text-foreground">{name}</span>
          </div>
        ))}
      </CardContent>
    </Card>
  )
}
```

### Disabled setting: the value stays readable, the reason is in the helper

A disabled slider is dimmed to 40 % and cannot be focused. Say why in the helper text instead of leaving people to guess.

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { SliderField } from "@/components/ui/slider"

export function Example() {
  return (
    <Card className="w-96 max-w-full">
      <CardHeader>
        <CardTitle>Notifications</CardTitle>
        <CardDescription>Workspace</CardDescription>
      </CardHeader>
      <CardContent>
        <SliderField label="Alert volume" unit="%" defaultValue={70} />
      </CardContent>
    </Card>
  )
}
```

## For AI agents

`get_component("slider")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
