Get Started
Input
Feedback
Display
Installation
i18n
import { Slider } from "@/components/ui/slider"
export function SliderDemo() {Installation#
pnpm dlx shadcn@latest add https://ui.tyap.me/r/styles/base/slider.jsonnpx shadcn@latest add https://ui.tyap.me/r/styles/base/slider.jsonyarn dlx shadcn@latest add https://ui.tyap.me/r/styles/base/slider.jsonbunx --bun shadcn@latest add https://ui.tyap.me/r/styles/base/slider.json
Install the following dependencies:
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/react
Copy and paste the following code into your project.
import { Slider as SliderPrimitive } from "@base-ui/react/slider"
import { cn } from "@/lib/utils"
function Slider({
className,
defaultValue,
value,
min = 0,
max = 100,
...props
}: SliderPrimitive.Root.Props) {
const _values = Array.isArray(value)
? value
: Array.isArray(defaultValue)
? defaultValue
: [min, max]
return (
<SliderPrimitive.Root
className={cn("data-horizontal:w-full data-vertical:h-full", className)}
data-slot="slider"
defaultValue={defaultValue}
value={value}
min={min}
max={max}
thumbAlignment="edge"
{...props}
>
<SliderPrimitive.Control className="relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-vertical:h-full data-vertical:w-auto data-vertical:flex-col">
<SliderPrimitive.Track
data-slot="slider-track"
className="relative grow overflow-hidden select-none"
>
<SliderPrimitive.Indicator
data-slot="slider-range"
className="select-none data-horizontal:h-full data-vertical:w-full"
/>
</SliderPrimitive.Track>
{Array.from({ length: _values.length }, (_, index) => (
<SliderPrimitive.Thumb
data-slot="slider-thumb"
key={index}
className="block shrink-0 select-none disabled:pointer-events-none disabled:opacity-50"
/>
))}
</SliderPrimitive.Control>
</SliderPrimitive.Root>
)
}
export { Slider }
Update the import paths to match your project setup.
Usage#
import { Slider } from "@/components/ui/slider"<Slider defaultValue={[33]} max={100} step={1} />Examples#
Range#
Use an array with two values for a range slider.
import { Slider } from "@/components/ui/slider"
export function SliderRange() {Multiple Thumbs#
Use an array with multiple values for multiple thumbs.
import { Slider } from "@/components/ui/slider"
export function SliderMultiple() {Vertical#
Use orientation="vertical" for a vertical slider.
import { Slider } from "@/components/ui/slider"
export function SliderVertical() {Controlled#
0.3, 0.7
"use client"
import * as React from "react"Disabled#
Use the disabled prop to disable the slider.
import { Slider } from "@/components/ui/slider"
export function SliderDisabled() {RTL#
To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import * as React from "react"API Reference#
See the Base UI Slider documentation.