Skip to main content
The Slider component allows users to select a single value or range of values by dragging handles along a track, supporting both horizontal and vertical orientations.

Installation

npx shadcn@latest add @eo-n/slider

Usage

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

export default function Example() {
  return <Slider defaultValue={[50]} max={100} step={1} />;
}

Examples

Default

<Slider defaultValue={[50]} max={100} step={1} />

Controlled

import { useState } from "react";

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

  return (
    <div className="space-y-4">
      <Slider value={value} onValueChange={setValue} max={100} step={1} />
      <p className="text-sm">Value: {value[0]}</p>
    </div>
  );
}

Disabled

<Slider defaultValue={[50]} disabled max={100} step={1} />

With Value Display

import { SliderValue } from "@/components/ui/slider";

<div className="space-y-2">
  <div className="flex items-center justify-between">
    <label className="text-sm font-medium">Volume</label>
    <SliderValue />
  </div>
  <Slider defaultValue={[75]} max={100} step={1} />
</div>

With Custom Min/Max

<Slider defaultValue={[25]} min={0} max={50} step={5} />

With Custom Step

<Slider defaultValue={[5]} min={0} max={10} step={0.5} />

Range Slider

Use multiple values for a range slider.
import { useState } from "react";

function RangeSlider() {
  const [value, setValue] = useState([25, 75]);

  return (
    <div className="space-y-4">
      <Slider value={value} onValueChange={setValue} max={100} step={1} />
      <p className="text-sm">
        Range: {value[0]} - {value[1]}
      </p>
    </div>
  );
}

Vertical Orientation

<Slider
  orientation="vertical"
  defaultValue={[50]}
  max={100}
  step={1}
  className="h-64"
/>

Vertical Range

<Slider
  orientation="vertical"
  defaultValue={[25, 75]}
  max={100}
  step={1}
  className="h-64"
/>

With Labels

import { SliderValue } from "@/components/ui/slider";
import { Label } from "@/components/ui/label";

function LabeledSlider() {
  return (
    <div className="space-y-4">
      <div className="flex items-center justify-between">
        <Label>Brightness</Label>
        <SliderValue className="text-xs" />
      </div>
      <Slider defaultValue={[80]} max={100} step={1} />
      <div className="flex justify-between text-xs text-muted-foreground">
        <span>0%</span>
        <span>100%</span>
      </div>
    </div>
  );
}

API Reference

Slider

Extends all props from @base-ui/react Slider.Root component.
value
number[]
The controlled value(s) of the slider.
defaultValue
number[]
The default value(s) when uncontrolled.
onValueChange
function
Callback fired when the value changes.
(value: number[]) => void
min
number
default:"0"
The minimum value.
max
number
default:"100"
The maximum value.
step
number
default:"1"
The step increment between values.
orientation
string
default:"horizontal"
The orientation of the slider.Options: horizontal | vertical
disabled
boolean
Whether the slider is disabled.
name
string
The name attribute for form submission.
minStepsBetweenThumbs
number
default:"0"
Minimum number of steps between range thumbs.
className
string
Additional CSS classes to apply.

SliderValue

Displays the current slider value(s).
className
string
Additional CSS classes to apply.
render
function
Custom render function for the value.
(value: number[]) => ReactNode

TypeScript

import { Slider as SliderPrimitive } from "@base-ui/react";

type SliderProps = React.ComponentProps<typeof SliderPrimitive.Root>;
type SliderValueProps = React.ComponentProps<typeof SliderPrimitive.Value>;

Styling Features

  • Smooth transitions on interactions
  • Focus ring on keyboard focus
  • Hover ring on mouse hover
  • Active ring while dragging
  • Disabled state styling
  • Primary color for track fill
  • Shadow effects for depth
  • Support for both orientations

Accessibility

  • Fully keyboard accessible (Arrow keys to adjust, Home/End for min/max)
  • Proper ARIA attributes
  • Focus visible indicators
  • Screen reader support with value announcements
  • Touch-friendly for mobile devices

Build docs developers (and LLMs) love