Get Started
Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Card
- Checkbox
- Collapsible
- Combobox
- Context Menu
- Date Picker (Lite)
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP (Lite)
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
import { Slider } from "@/components/ui/slider"
export function SliderDemo() {
return (
<Slider
defaultValue={[75]}
max={100}
step={1}
class="mx-auto w-full max-w-xs"
/>
)
}Installation
pnpm dlx shadcnui-hono-jsx@latest add slidernpx shadcnui-hono-jsx@latest add slideryarn dlx shadcnui-hono-jsx@latest add sliderbunx shadcnui-hono-jsx@latest add sliderThis component uses a small client script. add installs it into public/shadcn/; serve that directory at /shadcn/ and load the script on pages that use the component (see Client Scripts):
<script type="module" src="/shadcn/slider.js"></script>Usage
import { Slider } from "@/components/ui/slider"<Slider defaultValue={[33]} max={100} step={1} />Range
Use an array with two values for a range slider.
import { Slider } from "@/components/ui/slider"
export function SliderRange() {
return (
<Slider
defaultValue={[25, 50]}
max={100}
step={5}
class="mx-auto w-full max-w-xs"
/>
)
}Multiple Thumbs
Use an array with multiple values for multiple thumbs.
import { Slider } from "@/components/ui/slider"
export function SliderMultiple() {
return (
<Slider
defaultValue={[10, 20, 70]}
max={100}
step={10}
class="mx-auto w-full max-w-xs"
/>
)
}Vertical
Use orientation="vertical" for a vertical slider.
import { Slider } from "@/components/ui/slider"
export function SliderVertical() {
return (
<div class="mx-auto flex w-full max-w-xs items-center justify-center gap-6">
<Slider
defaultValue={[50]}
max={100}
step={1}
orientation="vertical"
class="h-40"
/>
<Slider
defaultValue={[25]}
max={100}
step={1}
orientation="vertical"
class="h-40"
/>
</div>
)
}Controlled
0.3, 0.7
import { Label } from "@/components/ui/label"
import { Slider } from "@/components/ui/slider"
export function SliderControlled() {
const value = [0.3, 0.7]
return (
<div class="mx-auto grid w-full max-w-xs gap-3">
<div class="flex items-center justify-between gap-2">
<Label for="slider-demo-temperature">Temperature</Label>
<span class="text-sm text-muted-foreground">{value.join(", ")}</span>
</div>
<Slider
id="slider-demo-temperature"
defaultValue={value}
min={0}
max={1}
step={0.1}
/>
</div>
)
}Disabled
Use the disabled prop to disable the slider.
import { Slider } from "@/components/ui/slider"
export function SliderDisabled() {
return (
<Slider
defaultValue={[50]}
max={100}
step={1}
disabled
class="mx-auto w-full max-w-xs"
/>
)
}RTL
To enable RTL support in shadcn/ui, see the RTL configuration guide.
// This example sets dir and uses useTranslation because this site is not RTL.
// In an RTL app you won't need them; see the RTL guide.
import {
type Translations,
useTranslation,
} from "@/components/language-selector"
import { Slider } from "@/components/ui/slider"
const translations: Translations = {
en: {
dir: "ltr",
values: {},
},
ar: {
dir: "rtl",
values: {},
},
he: {
dir: "rtl",
values: {},
},
}
export function SliderRtl() {
const { dir } = useTranslation(translations, "ar")
return (
<Slider
defaultValue={[75]}
max={100}
step={1}
class="mx-auto w-full max-w-xs"
dir={dir}
/>
)
}Notes
- Each thumb holds a native
<input type="range">(focusable, keyboard-operable and submitted withname). Pointer dragging, keeping range thumbs in order and moving the thumbs as values change need the client script/shadcn/slider.js(<script type="module" src="/shadcn/slider.js">); without it the initial values are shown and submitted. - Controlled state (
onValueChange),format,localeandlargeStepare not supported (Page Up and Page Down use the browser's step). - Accepts
classinstead ofclassName. - Upstream documentation: shadcn/ui Slider. See also Differences from shadcn/ui.
API Reference
See the Base UI Slider documentation.