coss.com Svelte

Slider

An input where the user selects a value from within a given range.

API Reference
Loading p-slider-1 preview…

Installation

pnpm dlx shadcn-svelte@latest add https://coss-sv.vercel.app/r/slider.json

Usage

<script lang="ts">
  import * as Slider from "$lib/components/ui/slider/index.js";
</script>

<Slider.Root aria-label="Volume" defaultValue={50} />

API Reference

Slider.Root

The root accepts a number or an array for range sliders. Use defaultValue for the initial value or bind:value for controlled state.

PropTypeDefaultDescription
valuenumber \| readonly number[]minCurrent value; an array creates a range slider
defaultValuenumber \| readonly number[]minInitial value for uncontrolled use
minnumber0Minimum allowed value
maxnumber100Maximum allowed value
stepnumber1Granularity the value changes by
largeStepnumber10Granularity for Page Up, Page Down, and Shift + Arrow
orientation"horizontal" \| "vertical""horizontal"Axis the slider runs along
disabledbooleanfalseDisables the thumb inputs and pointer interaction
minStepsBetweenValuesnumber0Minimum steps between neighboring thumbs
thumbCollisionBehavior"push" \| "swap" \| "none""push"Controls what happens when one thumb reaches another
thumbAlignment"center" \| "edge""edge"Aligns thumbs to the track; the COSS wrapper defaults to edge alignment
namestringName submitted with the form
formstringID of the owning form when the slider is outside it
onValueChange(value: number \| readonly number[]) => voidRuns whenever the value changes
onValueCommitted(value: number \| number[]) => voidRuns after pointer or keyboard input settles

Slider.Value

The value part displays the current formatted value and points to the thumb inputs.

The package also exports Slider.Control, Slider.Track, Slider.Indicator, Slider.Thumb, and Slider.Label for custom compositions. See the Shards Slider API for drag, keyboard, formatting, and form props.

Examples

For accessible labelling and validation, prefer using the Field component to wrap checkboxes. See the related example: Slider field.

With Label and Value

Loading p-slider-2 preview…

Range Slider

Loading p-slider-3 preview…

Vertical

Loading p-slider-4 preview…

Form Integration

Loading p-slider-5 preview…