Drag to adjust the display brightness.
Installation
$Terminal
npx shadcn@latest add https://sdk-components.thesqd.com/r/slider.jsonUsage
Import from the master file and compose. Pass a `variant` for the visual treatment.
TSImport
import { Slider, type SliderVariant } from "@/components/ui/slider";TSExample
import { Slider } from "@/components/ui/slider";
export function Example() {
return <Slider label="Opacity" defaultValue={20} unit="%" />;
}Composition
Anatomy of the Slider primitive.
Slider (single component — pass everything as props)
├── variant="default | ticks"
├── label={<ReactNode>} (text shown above the track / inside the ticks track)
├── caption={<ReactNode>} (helper text below the track)
├── value | defaultValue (number for single, number[] for range)
├── onValueChange={(v) => …} (controlled handler)
├── min / max / step (numeric bounds and increment)
├── unit="%" | "dB" | … (suffix appended to the displayed value)
├── formatValue={(v) => …} (full control over the rendered value)
├── showValue={boolean} (toggle the live value, default true)
├── prefixIcon / suffixIcon (icons rendered either side of the track, default variant)
├── ticks={number} (number of evenly-spaced tick marks, ticks variant)
├── orientation="horizontal | vertical"
└── disabled (read-only + muted styling)Default
Label above the track with a live value on the right. The canonical layout.
Inline ticks
Compact 10-high bar with the label inside the track on the left and the value on the right. The thumb only appears on hover or while dragging.
Drag to adjust the display brightness.
Step
Set a `step` value and the slider snaps to that increment as the user drags.
Step in 10
Range
Pass a 2-element array to `defaultValue`/`value` for a two-thumb range slider.
Vertical orientation
Stack vertical sliders for an EQ-style control surface.
Prefix and suffix icons
Bracket the track with iconography — volume, brightness, temperature, etc.
Description
Helper text rendered under the track.
Brightness of the image
Controlled
Drive the slider from external state via `value` + `onValueChange`.
Current temperature: 31°
Disabled
Read-only with muted styling.
API Reference
Props exposed by the Slider component.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "ticks" | "default" | Visual treatment. `default` is the classic label-above + 1.5-high bar. `ticks` is the compact 10-high inline bar with label/value inside the track. |
label | ReactNode | — | Field label. Rendered above the track (default) or inside the track on the left (ticks). |
caption | ReactNode | — | Helper text rendered below the track. |
value | number | number[] | — | Controlled value. Pass an array of length 2 for a range slider. |
defaultValue | number | number[] | — | Uncontrolled initial value. |
onValueChange | (value: number | number[]) => void | — | Called as the user drags or keys the slider. |
min | number | 0 | Minimum value. |
max | number | 100 | Maximum value. |
step | number | 1 | Increment between selectable values. |
unit | string | — | Suffix appended to the displayed value (e.g. `%`, `°`, `dB`). |
formatValue | (value: number | number[]) => ReactNode | — | Full control over the rendered value. Overrides `unit` when provided. |
showValue | boolean | true | Toggle the live value display. |
prefixIcon | ReactNode | — | Icon rendered to the left of the track (default variant only). |
suffixIcon | ReactNode | — | Icon rendered to the right of the track (default variant only). |
ticks | number | 11 | Number of evenly-spaced tick marks (ticks variant). |
orientation | "horizontal" | "vertical" | "horizontal" | Layout orientation. |
disabled | boolean | — | Disable interaction and dim the slider. |
className | string | — | Override or extend the resolved variant classes. |