shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/radix/slider.jsonnpx shadcn@latest add https://kit.dev/r/radix/slider.jsonpnpm dlx shadcn@latest add https://kit.dev/r/radix/slider.jsonyarn shadcn@latest add https://kit.dev/r/radix/slider.jsonThis component depends on Field. Install it first if you haven't already.
Install the following dependencies:
bun add radix-uinpm install radix-uipnpm add radix-uiyarn add radix-uiCopy and paste the following code into your project.
"use client";
import { Slider as SliderPrimitive } from "radix-ui";
import React from "react";
import { cn } from "@/lib/utils";
import { FieldLabel } from "@/components/ui/field";
export const Slider = (
props: React.ComponentProps<typeof SliderPrimitive.Root>
) => {
const {
className,
defaultValue,
value,
min = 0,
max = 100,
children,
...restUpdate 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
valuenumber[]): voiddefaultValue?number[]disabled?booleanform?stringinverted?booleanminStepsBetweenThumbs?numbername?stringstep?numberAttributeType
SliderThumb
div
PropType
valuenumber[]): voiddefaultValue?number[]disabled?booleanform?stringinverted?booleanmax?numbermin?numberminStepsBetweenThumbs?numbername?stringstep?numberAttributeType
SliderTrack
div
PropType
valuenumber[]): voiddefaultValue?number[]disabled?booleanform?stringinverted?booleanmax?numbermin?numberminStepsBetweenThumbs?numbername?stringstep?numberAttributeType
SliderRange
div
PropType
valuenumber[]): voiddefaultValue?number[]disabled?booleanform?stringinverted?booleanmax?numbermin?numberminStepsBetweenThumbs?numbername?stringstep?numberAttributeType
SliderLabel
PropType
valuenumber[]): voiddefaultValue?number[]disabled?booleanform?stringinverted?booleanmax?numbermin?numberminStepsBetweenThumbs?numbername?stringstep?numberAttributeType
SliderValue
PropType
valuenumber[]): voiddefaultValue?number[]disabled?booleanform?stringinverted?booleanmax?numbermin?numberminStepsBetweenThumbs?numbername?stringstep?numberAttributeType