Slider

A React range slider on Base UI with one or two thumbs, a value bubble that shows while dragging, formatted values, and a minimum thumb gap.

Loading preview

Examples

Practical examples and common states for the same installable component.

Sizes

Three heights map to the primitive control-height scale.

examples/slider-sizes.tsx
import { Slider } from "@/components/wensity/slider";
export function SliderSizes() {
return (
<div className="flex flex-col gap-6">
<Slider defaultValue={30} size="sm" label="Small" />
<Slider defaultValue={60} size="md" label="Medium" />
<Slider defaultValue={80} size="lg" label="Large" />
</div>
);
}

Range

Two thumbs with a keyboard-accessible minimum distance.

examples/slider-range.tsx
"use client";
import * as React from "react";
import { SliderRange } from "@/components/wensity/slider";
export function SliderRangeExample() {
const [range, setRange] = React.useState<[number, number]>([25, 75]);
return (
<SliderRange
value={range}
onValueChange={setRange}
minDistance={10}
label="Range"
/>
);
}

Custom step

Snap to increments of 10 with keyboard PageUp/PageDown for larger jumps.

examples/slider-custom-step.tsx
import { Slider } from "@/components/wensity/slider";
export function SliderCustomStep() {
return <Slider defaultValue={40} step={10} label="Step 10" />;
}

Disabled

Non-interactive state keeps track and thumb visible but muted.

examples/slider-disabled.tsx
import { Slider } from "@/components/wensity/slider";
export function SliderDisabled() {
return <Slider defaultValue={50} disabled label="Disabled" />;
}

Controlled

Parent state drives the slider; commit fires on drag end and keyup.

examples/slider-controlled.tsx
"use client";
import * as React from "react";
import { Slider } from "@/components/wensity/slider";
export function SliderControlled() {
const [value, setValue] = React.useState(40);
return (
<Slider
value={value}
onValueChange={setValue}
onValueCommitted={setValue}
formatValue={(v) => `${Math.round(v)}%`}
label="Controlled"
/>
);
}

Overview

Slider is a React and Tailwind CSS range slider built on Base UI, in Next.js or any React app, with a single thumb or two thumbs through SliderRange. A small bubble above the thumb shows the value only while you drag or focus it with the keyboard, and formatValue turns the number into a price, percentage, or unit. Arrow keys work out of the box, each thumb gets its own accessible label, and minDistance stops a range from collapsing onto itself. onValueChange fires on every step, so save expensive work for onValueCommitted, which fires once the drag ends.

Installation

Run the following command

~/your-project
pnpm dlx wensity@latest add slider

Usage

Import Slider from @/components/wensity/slider and render it anywhere in your React or Next.js app. The source lands in your own repo, so every prop, class and animation below is yours to edit.

app/example.tsx
import { Slider, SliderRange } from "@/components/wensity/slider";
export default function Example() {
return (
<>
<Slider defaultValue={40} />
<SliderRange defaultValue={[20, 80]} minDistance={10} />
</>
);
}

Props

PropTypeDefaultDescription
valuenumber-Controlled value.
defaultValuenumber0Initial value when uncontrolled.
minnumber0Lowest selectable value.
maxnumber100Highest selectable value.
stepnumber1Granularity of movement.
onValueChange(value: number) => void-Called continuously as the thumb moves.
onValueCommit(value: number) => void-Called once when the drag ends. Use for expensive updates.
size"sm" | "md" | "lg""md"Track and thumb size.
tone"neutral" | "brand""brand"Colour of the filled track.
showValuebooleantrueShows the current value beside the label.
formatValue(value: number) => string-Formats the displayed value, for units or currency.
labelstring"Slider"Accessible label for the slider.
disabledbooleanfalseDisables the slider.
  • Gooey Range Slider component preview

    Gooey Range Slider

    Drag the thumb and the filled track stretches with it, then the thumb contracts into a circle when you let go.

  • Image Comparison Slider component preview

    Image Comparison Slider

    Drag the handle to wipe between before and after images with absolutely zero lag.

  • Water Progress Bar component preview

    Water Progress Bar

    A progress bar that fills with water, its rippling front leaning as it runs.

  • Liquid Loading Animation component preview

    Liquid Loading Animation

    A loader that fills with liquid to your progress, in a glass circle, square, or word.