Skip to main content

Starwind UI v1.15 is now available! With new prose, sidebar, and more components

Slider

Installation

Usage

General Notes

The Slider component provides an accessible way to select values within a range. It supports:

  • Single value selection: Default mode with one thumb
  • Range selection: Pass an array to defaultValue for two thumbs
  • Keyboard navigation: Arrow keys, Page Up/Down, Home/End
  • Form integration: Works with native form submission via hidden inputs

Range Slider

Pass an array of two values to create a range slider with two thumbs.

With Step

Use the step prop to control the increment value.

Variants

The slider supports multiple color variants.

Disabled

Vertical Orientation

Set orientation="vertical" for a vertical slider. Make sure to provide a container with a defined height.

Form Submission

The slider includes hidden <input type="range"> elements for native form submission. For range sliders, the inputs are named with array notation (e.g., price[0], price[1]).

Submit the form to see values

API Reference

Slider

An accessible slider component for selecting values within a range.

PropTypeDefault
defaultValuenumber | number[]0
valuenumber | number[]-
minnumber0
maxnumber100
stepnumber1
largeStepnumber10
orientation"horizontal" | "vertical""horizontal"
disabledbooleanfalse
namestring-
variant"default" | "primary" | "secondary" | "info" | "success" | "warning" | "error""default"
aria-labelstring-
aria-labelledbystring-
classstring-
<Slider
defaultValue={50}
min={0}
max={100}
step={5}
variant="primary"
aria-label="Volume"
/>

Additional Notes:

  • defaultValue: Initial value(s). Pass an array for range sliders
  • value: Controlled value (use with JavaScript event handlers)
  • largeStep: Step size for Page Up/Down and Shift+Arrow keys
  • orientation: Set to "vertical" for vertical sliders. Requires a container with defined height
  • name: Form field name. For range sliders, creates inputs named name[0] and name[1]

Events

The slider emits custom events for JavaScript integration:

EventDetailDescription
slider-change{ value: number | number[] }Fired on every value change during interaction
slider-commit{ value: number | number[] }Fired when interaction ends (pointer up)
<Slider id="my-slider" defaultValue={50} aria-label="Volume" />
<script>
const slider = document.getElementById("my-slider");
slider.addEventListener("slider-change", (e) => {
console.log("Value changed:", e.detail.value);
});
slider.addEventListener("slider-commit", (e) => {
console.log("Final value:", e.detail.value);
});
</script>

Changelog

v1.0.0

  • Initial release with starwind v1.13.0