Skip to main content

Starwind UI v3.0 is now available! Migration guide

Installation

Usage

---
import { Slider } from "@/components/starwind/slider";
---
<Slider defaultValue={25} aria-label="Volume" />

Behavior

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

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Slider

Inherits div attributes. Omits `defaultValue`, `onChange`, and `value`.

Contains the following additional props:

Prop Type Default Toggle details
defaultValue number | number[] 0
Description
Sets the initial value when the component is uncontrolled.
Classification
Primitive override
Type imports
React import type { SliderValue } from "@starwind-ui/react";
Primitive prop
slider.Root.defaultValue
orientation "horizontal" | "vertical" "horizontal"
Description
Selects the horizontal or vertical layout direction.
Classification
Primitive override
Primitive prop
slider.Root.orientation
value number | number[] —
Description
Controls or identifies the component value.
Classification
Primitive override
Type imports
React import type { SliderValue } from "@starwind-ui/react";
Primitive prop
slider.Root.value
variant "default" | "primary" | "secondary" | "info" | "success" | "warning" | "error" "default"
Description
Selects the component's visual variant.
Classification
Styled variant

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Slider.

Primitive API

Runtime API

Slider primitive
createSlider from @starwind-ui/runtime/slider

Changelog

View version history v2.1.0 6 releases

v2.1.0

  • In Svelte, a defined value that you pass when Slider mounts now stays under your control, as in React and Vue. To change it, use bind: or update your state in the change callback. A form reset keeps it. If you pass undefined at mount, Slider keeps its own state.
  • Fixed a bound Slider in Svelte that reset to 0.

v2.0.2

  • Reduced the JavaScript loaded by Slider when it is used without Field.

v2.0.1

  • In React, you can cancel a change before it applies. The component then keeps its previous state, and it shows only the changes that apply.

v2.0.0

  • Slider now gets its behavior from Starwind Runtime. Runtime handles the values, the keyboard, dragging, and the native form value.
  • See the Slider Primitive for the unstyled parts and the behavior API.

v1.0.2

  • The Tailwind variants now live in their own variants.ts file in the component folder.

v1.0.0

  • Initial release with starwind v1.13.0