# Slider

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/slider
- **Markdown:** https://refast.fastapicloud.dev/docs/components/slider.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/buttons/slider.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

A draggable range slider for selecting a numeric value (or range).

```python
from refast.components.shadcn.controls import Slider

# Basic slider
Slider(value=[50], min=0, max=100, on_value_change=ctx.callback(handle_change))

# With label and description
Slider(
    label="Volume",
    description="Adjust the output volume",
    value=[volume],
    show_value=True,
    on_value_change=ctx.callback(handle_volume),
)

# Vertical slider
Slider(value=[50], orientation="vertical", class_name="h-40")
```

Current value: 50

```python
Slider(
    value=[50],
    min=0,
    max=100,
    step=1,
    orientation="horizontal",
    disabled=False,
    show_value=True,
    on_value_change=ctx.callback(handle_change),
)
```

## Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `value` | `list[float] \| None` | `None` | Controlled value(s) — a list allows range sliders |
| `default_value` | `list[float] \| None` | `[0]` | Initial value (uncontrolled) |
| `min` | `float` | `0` | Minimum value |
| `max` | `float` | `100` | Maximum value |
| `step` | `float` | `1` | Increment between values |
| `disabled` | `bool` | `False` | Prevents interaction |
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Slider direction |
| `label` | `str \| None` | `None` | Visible label above the slider |
| `description` | `str \| None` | `None` | Helper text below the slider |
| `show_value` | `bool` | `False` | Display current value next to thumb |
| `required` | `bool` | `False` | Marks the field as required |
| `error` | `str \| None` | `None` | Validation error message |
| `on_value_change` | `Callback \| None` | `None` | Called continuously while dragging |
| `on_value_commit` | `Callback \| None` | `None` | Called once when the user releases the thumb |
| `class_name` | `str` | `""` | Extra Tailwind classes |

## Controlled Usage

```python
async def handle_volume(ctx: Context, value: list):
    ctx.state.set("volume", value[0])
    await ctx.refresh()

Slider(
    value=[ctx.state.get("volume", 50)],
    min=0,
    max=100,
    on_value_change=ctx.callback(handle_volume),
)
```

## on_value_change vs on_value_commit

```python
# on_value_change fires on every drag tick — good for live preview
Slider(value=[v], on_value_change=ctx.callback(handle_live))

# on_value_commit fires only when the thumb is released — good for expensive operations
Slider(value=[v], on_value_commit=ctx.callback(handle_commit))
```

## Range Slider

Pass two values to create a range slider with two thumbs:

```python
Slider(
    value=[20, 80],
    min=0,
    max=100,
    on_value_change=ctx.callback(handle_range),
)
```

## Vertical

```python
Slider(
    value=[50],
    orientation="vertical",
    class_name="h-40",
    on_value_change=ctx.callback(handle_change),
)
```

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
