Inputs & controlsstable

    Slider

    A tactile slider with a glossy pill track, raised thumb, keyboard controls, and range selection.

    Follow the installation and quick start below to use Slider in your project, or read the complete setup guide.

    Accessible by designLight & darkCopy. Customize. Ship.
    On this page
    Live previewFluid
    50%

    Drag to adjust. Use arrow keys for finer control.

    Interactive exampleReact / TypeScript / Tailwind CSS
    ADD TO YOUR PROJECT

    Installation

    1. Initialize once

    Run from an existing React project with Node.js 18 or later. Skip this step if the project already has u-lib.json. Initialization copies the shared stylesheet and adds its import to your application entry.

    npx @scriptwithahmad/u-lib@0.2.2 init

    2. Add Slider and example components

    This command includes the UI components used by this page's usage examples. The CLI copies editable source into your components directory and installs each component's dependencies. Existing source files are preserved.

    npx @scriptwithahmad/u-lib@0.2.2 add slider

    Choose the tab for your package manager. Yarn commands require modern Yarn; Yarn Classic users can use npx. Use --dry-run to preview changes. See the installation guide for custom paths, JavaScript output and package-import alternatives.

    USE IN YOUR APP

    Quick start

    Copy this example into src/Example.tsx (or Example.tsx at the project root when you do not use src). Imports assume the default CLI paths. From a nested file such as src/app/page.tsx, adjust ./components to ../components. Keep the client directive in Next.js when using state or event handlers.

    slider-example.tsx
    "use client";
    import { useState } from "react";
    import { Slider } from "./components/ui/slider";
    export default function PriceRange() {
      const [values, setValues] = useState([20, 80]);
      return <div className="w-full max-w-md space-y-3 px-4 py-6">
        <div className="flex items-center justify-between gap-3 text-sm"><span>Price range</span><output className="tabular-nums text-muted-foreground">{values[0]} to {values[1]} USD</output></div>
        <Slider aria-label="Price range" value={values} onValueChange={setValues} min={0} max={100} step={5} minStepsBetweenThumbs={1} />
      </div>;
    }

    Values use arrays: one value for a single thumb, or multiple values for a range. Keep an accessible label and use onValueChange for controlled state.

    Keep the shared stylesheet imported once. Replace sample image URLs and data with your own. Examples may use layout utilities beyond the precompiled component styles; compile added Tailwind classes in your app or replace them with your own CSS. Customize local source or className, and preserve accessible names and keyboard behavior.

    BUILD WITH IT

    Usage examples

    3 examples

    Try each example, then switch to Code to copy its complete implementation. These catalog snippets use the website's @/components/ui alias; replace it with your local generated path as shown in Quick start.

    01

    Price range

    Adjust minimum and maximum prices with two independently labeled thumbs.

    Price range

    Loading example…

    02

    Stepped slider

    Choose a value in increments of ten.

    Stepped slider

    Loading example…

    03

    Disabled slider

    An unavailable slider that cannot be adjusted.

    Disabled slider

    Loading example…

    THE API

    Props & configuration

    Reference

    Everything you need to fine-tune this component.

    Props and configuration
    PropTypeDefaultDescription
    valuenumber[]—Controlled values, with one thumb per value.
    defaultValuenumber[][0]Initial uncontrolled values.
    onValueChange(value: number[]) => void—Called as the value changes.
    onValueCommit(value: number[]) => void—Called when a pointer or keyboard adjustment is committed.
    minnumber0Minimum value.
    maxnumber100Maximum value.
    stepnumber1Step between values.
    disabledbooleanfalseDisables all thumbs.
    aria-labelstring—Accessible name, applied to each thumb.
    orientation"horizontal" | "vertical"horizontalTrack direction.