Slider

Form

Range slider for numeric value selection.

Preview

Volume

Brightness (min: 20)

Usage

example.jsx
import { Slider } from "@/components/ui/slider";

export default function Example() {
  return <Slider />;
}

Source Code

Copy this file into components/ui/slider.jsx in your project.

slider.jsx
"use client";

import { forwardRef } from "react";
import { cn } from "@/lib/utils";

const Slider = forwardRef(({ className, min = 0, max = 100, step = 1, value, onValueChange, ...props }, ref) => {
  return (
    <input
      ref={ref}
      type="range"
      min={min}
      max={max}
      step={step}
      value={value}
      onChange={(e) => onValueChange?.(Number(e.target.value))}
      className={cn(
        "w-full h-2 rounded-full appearance-none cursor-pointer bg-secondary",
        "accent-primary",
        "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
        "disabled:cursor-not-allowed disabled:opacity-50",
        className
      )}
      {...props}
    />
  );
});
Slider.displayName = "Slider";

export { Slider };

Quick Install

Make sure you have the cn() utility set up. It requires clsx and tailwind-merge.

npm install clsx tailwind-merge