shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/base/slider.jsonnpx shadcn@latest add https://kit.dev/r/base/slider.jsonpnpm dlx shadcn@latest add https://kit.dev/r/base/slider.jsonyarn shadcn@latest add https://kit.dev/r/base/slider.jsonThis component depends on Field. Install it first if you haven't already.
Install the following dependencies:
bun add @base-ui/reactnpm install @base-ui/reactpnpm add @base-ui/reactyarn add @base-ui/reactCopy and paste the following code into your project.
"use client";
import { Slider as SliderPrimitive } from "@base-ui/react/slider";
import type React from "react";
import { cn } from "@/lib/utils";
import { FieldLabel } from "@/components/ui/field";
export const Slider = (props: SliderPrimitive.Root.Props) => {
const {
className,
defaultValue,
value,
min = 0,
max = 100,
children,
...rest
} = props;
Update the import paths to match your project setup.
Anatomy
Slider
├── SliderLabel
├── SliderThumb
├── SliderValue
├── SliderTrack
├── SliderRange
├── SliderControl
├── SliderMarkerGroup
├── SliderMarker
└── SliderDraggingIndicatorUsage
import { Slider } from "@/components/ui/slider";<Slider
className="mx-auto w-full max-w-xs"
defaultValue={[75]}
max={100}
step={1}
/>Accessibility
| Key | Description |
|---|---|
ArrowUp | Increase the value when orientation is "vertical". |
ArrowDown | Decrease the value when orientation is "vertical". |
ArrowLeft | Decrease the value when orientation is "horizontal". |
ArrowRight | Increase the value when orientation is "horizontal". |
PageUp | Increase the value. |
PageDown | Decrease the value. |
Home | Go to the start. |
End | Go to the end. |
Demos
Range
Use an array with two values for a range slider.
Multiple
Use an array with multiple values for multiple thumbs.
Vertical
Use orientation="vertical" for a vertical slider.
Controlled
Controlled slider with a live value readout.
Disabled
Use the disabled prop to disable the slider.
Rtl
Right-to-left slider. See the RTL configuration guide for document direction.
API Reference
Slider
div
PropType
AttributeType
SliderThumb
div
PropType
AttributeType
SliderTrack
div
AttributeType
SliderControl
div
AttributeType
SliderLabel
PropType
AttributeType
SliderValue
PropType
AttributeType