GitHub
Core
Glass
Brutal
Humanist

Slider

Sliders allow users to select a value or range from a continuous set. They support single value and range modes, value indicators, labels, and custom step increments.

Slider Playground

Slider Playground
Preview
Code
0100
Controls
Type:
Default
Range
Labels:
Value Indicator:
Disabled:

Installation

You can add the slider component to your project manually:

1

Install the following dependencies:

npm install class-variance-authority clsx tailwind-merge
2

Copy and paste the following code into your project.

Loading source code...
3

Update the import paths to match your project setup.

Update the import aliases (e.g. @/components, @/utils) in the copied files to match your project's path configuration.

Basic Usage

import { useState } from 'react';
import { Slider } from '@versaui/ui/components/Slider';

function Example() {
  const [value, setValue] = useState(50);

  return (
    <Slider
      value={value}
      onChange={(val) => setValue(val)}
    />
  );
}

Range Slider

Select a range between two values:

const [range, setRange] = useState<[number, number]>([25, 75]);

<Slider
  type="range"
  values={range}
  onRangeChange={(values) => setRange(values)}
/>

With Labels

Show a label above the slider and min/max values at the ends:

<Slider
  label="Volume"
  showMinMaxLabels
  value={50}
  onChange={(val) => console.log(val)}
/>

Value Indicator

A tooltip showing the current value appears on hover and during drag (enabled by default):

// Enabled by default
<Slider value={50} />

// Disable the value indicator
<Slider value={50} showValueIndicator={false} />

Step Increments

Control the granularity of value selection:

<Slider
  min={0}
  max={100}
  step={10}
  value={50}
/>

Custom Width

<Slider width={400} />
<Slider width="100%" />

Disabled State

<Slider disabled value={30} />

Accessibility

  • Uses role="slider" with aria-valuenow, aria-valuemin, aria-valuemax
  • Arrow keys adjust value by step, Home/End jump to min/max
  • Label association via aria-label
  • Focus ring visible on keyboard navigation
  • Grab cursor on hover, grabbing cursor while dragging

Slider Props

PropTypeDefaultDescription
type'default' | 'range''default'Single value or range mode.
valuenumber50Current value (single mode).
values[number, number][25, 75]Current range values (range mode).
minnumber0Minimum value.
maxnumber100Maximum value.
stepnumber1Step increment.
disabledbooleanfalsePrevents interaction.
showValueIndicatorbooleantrueShow value tooltip on hover/drag.
labelstringLabel text above slider.
showMinMaxLabelsbooleanfalseShow min/max values at track ends.
onChange(value: number) => voidCalled when single value changes.
onRangeChange(values: [number, number]) => voidCalled when range values change.
widthnumber | string200Width of the slider.
classNamestring''Additional CSS classes.

On this page