<!--
Source: https://www.theui.dev/docs/range
Part of the theui-svelte documentation. Index: https://www.theui.dev/llms.txt
-->

# Range

The Range component lets the user choose a number by dragging a handle. It is a native range input underneath, so the keyboard, touch and screen readers all work, while the track, the handle and the value bubble follow your theme.

## Example

Import the component, bind a number and give it a label as the child. The track fills up to the value as it moves.

```html
<script>
  import { Range } from "theui-svelte";
  let volume = $state(40)
</script>

<Range bind:value={volume}>Volume</Range>
```

## Min, Max and Step

Use `min`, `max` and `step` the way you would on a native input. The default range is `0` to `100` in steps of `1`.

```html
<Range value={30} min={0} max={100} step={10}>Steps of 10</Range>
<Range bind:value={temperature} min={10} max={30} step={0.5}>Half degrees</Range>
```

## Showing the Value

Set `showValue` to put the number beside the slider, or `showValue="tooltip"` to float it above the handle as it moves.

```html
<Range bind:value={volume} showValue>Inline value</Range>
<Range bind:value={volume} showValue="tooltip">Value bubble</Range>
```

## Formatting

The `format` prop turns the number into the text that is shown, for money, units or anything else. It is used by the inline value, the bubble and the text read out to screen readers.

```html
<Range bind:value={budget} min={0} max={1000} step={10} showValue="tooltip" format={(v) => `$${v}`}>
  Budget
</Range>

<Range bind:value={temperature} min={10} max={30} step={0.5} showValue format={(v) => `${v} °C`}>
  Temperature
</Range>
```

## Ticks

Pass `ticks` to mark places along the track. Give it plain numbers, or objects with your own text.

```html
<Range bind:value={temperature} min={10} max={30} ticks={[10, 15, 20, 25, 30]}>Numbers</Range>

<Range
  value={2}
  min={1}
  max={4}
  ticks={[
    {value: 1, label: "Low"},
    {value: 2, label: "Fair"},
    {value: 3, label: "Good"},
    {value: 4, label: "Best"}
  ]}
>Labels</Range>
```

## Sizes

The `size` prop takes `sm`, `md`, `lg` and `xl`, changing the thickness of the track and the size of the handle. Inside a [Form](https://www.theui.dev/docs/form) or a [Fieldset](https://www.theui.dev/docs/fieldset) the size is inherited, so you set it once.

```html
<Range value={40} size="sm" />
<Range value={40} size="md" />
<Range value={40} size="lg" />
<Range value={40} size="xl" />
```

## Helper Text and Disabled

Add `helperText` to explain the field, and `disabled` to switch it off. The helper text is linked to the input, so screen readers read it with the label.

```html
<Range value={60} helperText="Drag, or use the arrow keys">Quality</Range>
<Range value={60} disabled>Disabled</Range>
```

## Reset Styles

Set `reset` to `true` to drop the custom track and thumb and hand the control back to the browser, so the slider is drawn the way the operating system draws it. Anything you pass in `rangeClasses` still applies, and the size variables stay, so the label and the helper text are unchanged. The default is `false`, and a [Form](https://www.theui.dev/docs/form) or a [Fieldset](https://www.theui.dev/docs/fieldset) can set it for every field it holds.

```html
<Range reset rangeClasses="w-full accent-brand-500">Native slider</Range>
```

## Customization

The colour of the filled track and the handle follows the text colour, so a single class recolours both. Use `rangeClasses` for the input itself and `wrapperClasses` for the field around it.

```html
<Range value={40} class="text-info-500" />
<Range value={60} class="text-success-500" size="lg" />
<Range value={80} class="text-error-500" size="xl" showValue />
```

## Accessibility

The component is a native `<input type="range">`, so the browser gives it the slider role, the minimum, maximum and current value, and the usual keys: the arrows move by one step, Page Up and Page Down move in bigger jumps, and Home and End go to the ends. The label you pass is tied to the input, and `helperText` is linked with `aria-describedby`. Where the number needs words, such as a price or a temperature, the `format` function is used for the spoken value as well. The fill direction follows the page, so a right to left page fills from the right.

## Configuration

### Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | number | `0` | The chosen number. Bindable with `bind:value`. |
| `min` | number | `0` | Lowest value of the range. |
| `max` | number | `100` | Highest value of the range. |
| `step` | number | `1` | How far the value moves at a time. |
| `showValue` | boolean \| "inline" \| "tooltip" | `false` | Shows the value beside the slider, or in a bubble over the handle with "tooltip". |
| `format` | (value: number) => string | `(v) => String(v)` | Turns the number into the text shown, and into the value read by screen readers. |
| `ticks` | [RANGE_TICK](https://www.theui.dev/docs/types#range-tick-type)[] | `undefined` | Marks under the track. Numbers, or objects with a value and a label. |
| `reset` | boolean | `Inherited from Fieldset or Form, or false` | Resets all default styles and applies only custom styles. |
| `size` | [INPUT_SIZE](https://www.theui.dev/docs/types#input-size-type) | `md` | Thickness of the track and size of the handle. Inherited from Form or Fieldset. |
| `helperText` | string \| Snippet | `undefined` | Text under the field, linked to the input for screen readers. |
| `labelClasses` | string | `` | Custom classes for the label. |
| `wrapperClasses` | string | `` | Custom classes for the field wrapper. |
| `rangeClasses` | string | `` | Custom classes for the range input itself. |

### Dynamic props

| Name | Description |
| --- | --- |
| `class` | Classes for the range input, merged with the default classes. The filled track and the handle follow the text colour. |
| `disabled` | Switches the field off. |
| `name` | Name of the field, so the value is submitted with the form. |

### Snippets

| Name | Description |
| --- | --- |
| `children` | Label of the field. |

---

Category: Forms
Keywords: range, slider, input, form, component, svelte, svelte-5, theui-svelte, component-library, ui, tailwindcss
Full documentation set: https://www.theui.dev/llms-full.txt
