Slider
A number in a range, with a visible value and arrow-key steps.
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import SliderExample from './SliderExample.svelte';
</script>
<SliderExample step={1} disabled={false} />
<script lang="ts">
import { Slider } from 'portal-bits';
let { disabled = false, step = 1 }: { disabled?: boolean; step?: number } = $props();
let volume = $state(40);
</script>
<div class="field">
<Slider
label="Preview volume"
bind:value={volume}
{step}
{disabled}
format={(value) => `${value}%`}
/>
</div>
<style>
.field {
width: 320px;
max-width: 100%;
}
</style>
API reference
These tables list the props and snippets that Slider declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
label | string | None | Yes | One-way | The visible label. It names the thumb. |
value | number | 0 | No | Bindable | The current value. |
min | number | 0 | No | One-way | The lowest value. |
max | number | 100 | No | One-way | The highest value. |
step | number | 1 | No | One-way | The amount one arrow key press moves. |
disabled | boolean | false | No | One-way | Stops pointer and keyboard changes. |
name | string | None | No | One-way | Submits the value with a form under this name. |
format | (value: number) => string | String(value) | No | One-way | Formats the visible value and `aria-valuetext`, such as `40%`. |
class | string | "" | No | One-way | Extra classes, added after the component classes. |
Forwarded attributes
None. Slider forwards no attributes.
The primitive underneath is a Bits UI peer dependency. Its own options are documented in the Bits UI Slider documentation. Only the props listed on this page are part of the Slider contract. No data attributes are documented as stable.
Limits
- One thumb only. Ranges with two thumbs are not supported.
- Horizontal only. The track, thumb, and halo are an adaptation; no slider was measured.
- Only the props listed here reach Bits UI `Slider.Root`.