- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Calendar
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- ComposerNew
- Command
- Context Menu
- Date Picker
- Dialog
- Drawer
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Meter
- Number Field
- OTP Field
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Segmented Control
- Separator
- Sheet
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Slider
An input where the user selects a value from within a given range.
"use client";
import { Slider } from "@/components/ui/slider";
export default function Particle() {
return <Slider getAriaLabel={() => "Value"} defaultValue={50} />;
}
Installation
pnpm dlx shadcn@latest add @coss/slider
Usage
import { Slider, SliderValue } from "@/components/ui/slider"<Slider getAriaLabel={() => "Volume"} />API Reference
Slider
Root component. Styled wrapper for Slider.Root from Base UI with default min/max values and edge-aligned thumbs.
| Prop | Type | Default | Description |
|---|---|---|---|
min | number | 0 | Minimum value of the slider |
max | number | 100 | Maximum value of the slider |
getAriaLabel | (index: number) => string | — | Accessible name for each generated thumb |
Note: The component sets thumbAlignment="edge" by default, which aligns thumbs to the edge of the track rather than centering them.
SliderValue
Displays the current value. Styled wrapper for Slider.Value from Base UI.
Examples
For accessible labelling and validation, prefer using the Field component with an associated FieldLabel. See the related example: Slider field.
Use getAriaLabel when there is no associated label. Name each range endpoint separately:
<Slider
defaultValue={[20, 80]}
getAriaLabel={(index) => index === 0 ? "Minimum price" : "Maximum price"}
/>Callbacks such as getAriaLabel must be supplied from a Client Component. An associated FieldLabel continues to work without this prop. Setting aria-label on the root alone does not name its thumbs.
With Label and Value
import { Field, FieldLabel } from "@/components/ui/field";
import { Slider, SliderValue } from "@/components/ui/slider";
export default function Particle() {
return (
<Field>
<Slider defaultValue={50}>
<div className="mb-2 flex items-center justify-between gap-1">
<FieldLabel className="font-medium text-sm">Opacity</FieldLabel>
<SliderValue />
</div>
</Slider>
</Field>
);
}
Range Slider
import { Slider } from "@/components/ui/slider";
export default function Particle() {
return <Slider defaultValue={50} disabled />;
}
Vertical
"use client";
import { Slider } from "@/components/ui/slider";
export default function Particle() {
return (
<div>
<Slider
getAriaLabel={() => "Storage size in GB"}
defaultValue={15}
max={35}
min={5}
/>
<div
aria-label="Storage size reference values"
className="mt-4 flex w-full items-center justify-between gap-1 font-medium text-muted-foreground text-xs"
role="group"
>
<span>5 GB</span>
<span>20 GB</span>
<span>35 GB</span>
</div>
</div>
);
}
Form Integration
"use client";
import { cn } from "@/lib/utils";
import { Slider } from "@/components/ui/slider";
const max = 12;
const skipInterval = 2;
const ticks = [...Array(max + 1)].map((_, i) => i);
export default function Particle() {
return (
<div>
<Slider
getAriaLabel={() => "Value selector"}
defaultValue={5}
max={max}
/>
<div
aria-label="Value scale from 0 to 12"
className="mt-3 flex w-full items-center justify-between gap-1 px-2.5 font-medium text-muted-foreground text-xs"
role="group"
>
{ticks.map((_, i) => (
<span
className="flex w-0 flex-col items-center justify-center gap-2"
key={String(i)}
>
<span
className={cn(
"h-1 w-px bg-muted-foreground/72",
i % skipInterval !== 0 && "h-0.5",
)}
/>
<span className={cn(i % skipInterval !== 0 && "opacity-0")}>
{i}
</span>
</span>
))}
</div>
</div>
);
}