Picks a value from a range by dragging a thumb, pressing the track, or using the keyboard. Each thumb has role="slider", so give the slider an aria-label, which passes to the thumb, or name each thumb with thumbLabels.
<script lang="ts">
import { Slider } from "#lib/components/ui/slider/index.js";
</script>
<Slider defaultValue={[33]} max={100} step={1} aria-label="Volume" />pnx remote0 add https://plainsv.com/r/slider.jsonThe value is an array with one number per thumb. Set defaultValue to start from a value and let the slider manage it, or use bind:value to read and set it from your own state. Without either, the slider starts at min. Values snap to step and stay between min and max.
Pass two values to get two thumbs with the track filled between them. Thumbs cannot pass each other, and pressing the track moves the closest one.
$25 to $75
<script lang="ts">
import { Slider } from "#lib/components/ui/slider/index.js";
let priceRange = $state([25, 75]);
</script>
<Slider bind:value={priceRange} step={5} thumbLabels={["Minimum price", "Maximum price"]} />
<p>${priceRange[0]} to ${priceRange[1]}</p>onValueChange runs on every change while dragging. onValueCommit runs once when a drag ends or a key moves a thumb, which suits saving or fetching.
Committed volume: 50
<Slider defaultValue={[50]} aria-label="Volume" onValueCommit={(next) => saveVolume(next[0])} />Focus a thumb with Tab. The arrow keys move it by one step, and Shift with an arrow or Page Up and Page Down move it by ten. Home and End jump to min and max.
Set orientation="vertical" to run the track from bottom to top. A vertical slider fills its parent's height, with a minimum of 10rem.
<div style="height: 10rem">
<Slider orientation="vertical" defaultValue={[50]} aria-label="Bass" />
</div>Set name to submit the slider with a form. Each value renders as a hidden input with that name, so a range submits two fields.
<form method="POST">
<Slider name="price" defaultValue={[25, 75]} thumbLabels={["Minimum price", "Maximum price"]} />
</form>Set variant to default or destructive to color the range and thumbs.
<Slider variant="destructive" defaultValue={[33]} aria-label="Volume" />Set size to xs, sm, md, or lg to change the track thickness and thumb size. The default is md, and the corner radius follows the size.
<Slider size="lg" defaultValue={[33]} aria-label="Volume" />Set rounded to xs through 4xl or pill to override the radius of the track and thumbs. Use pill for round thumbs at every size.
<Slider rounded="pill" defaultValue={[33]} aria-label="Volume" />Set disabled to dim the slider and block pointer and keyboard input. Disabled thumbs leave the tab order.
<Slider disabled defaultValue={[33]} aria-label="Volume" />The Slider props extend the native div attributes, and extra attributes pass through to the root. aria-label and aria-labelledby move to each thumb instead.
interface Props extends CompProps<"div"> {
/** Thumb values from `min` to `max`, in order; supports `bind:value` */
value?: number[];
/** Starting values when `value` is not set; defaults to `[min]` */
defaultValue?: number[];
/** Lowest value; defaults to `0` */
min?: number;
/** Highest value; defaults to `100` */
max?: number;
/** Amount each value snaps to; defaults to `1` */
step?: number;
/** Direction of the track; `vertical` fills its parent's height */
orientation?: "horizontal" | "vertical";
/** Dims the slider and blocks pointer and keyboard input */
disabled?: boolean;
/** Form field name; each value submits as a hidden input with this name */
name?: string;
/** Accessible name for each thumb, such as `["Minimum", "Maximum"]`; falls back to `aria-label` */
thumbLabels?: string[];
/** Called with the new values on every change while dragging or typing */
onValueChange?: (value: number[]) => void;
/** Called with the final values when a drag ends or a key changes them */
onValueCommit?: (value: number[]) => void;
/** Visual style of the range and thumbs */
variant?: "default" | "destructive";
/** Track thickness and thumb size on the shared scale; defaults to `md` */
size?: UiSize;
/** Corner radius of the track and thumbs; follows `size` when omitted */
rounded?: UiRounded;
}