Skip to content

Slider

slider

A value or a range on a track: a rolling-digit readout, a value bubble over each thumb while it is in use, ticks that go pale once the fill passes them, pressable mark labels, and an optional icon or control beside it. Arrows, Page Up and Down, Home and End and range-thumb collision handling come from the Base UI slider.

Install

$npxshadcnadd@forme/slider

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import { Slider } from "@/components/forme/slider/slider";

<Slider
  label="Budget"
  defaultValue={[2000, 8000]}
  min={0}
  max={10000}
  step={250}
  formatValue={(value) => `$${value.toLocaleString("en-US")}`}
  thumbLabels={["Minimum budget", "Maximum budget"]}
/>

When to use

Reach for it

  • A number where the useful feedback is the position rather than the digits: a budget, a volume, a threshold.
  • A range, by passing an array. Both thumbs share the track and cannot cross.
  • marks when the scale needs landmarks: every mark draws a tick, and a { value, label } also prints it under the track as a preset — pressing it moves the nearest thumb there.
  • start or end for the control that belongs with it — a mute button, a preset reset.

Use something else

  • A precise number the reader has to type or read exactly; that is an Input, where the digits are the point.
  • Two or three discrete choices; a SegmentedControl names each one and needs no dragging.
  • Anything where being off by a step changes meaning, unless step is small and the marks show the grid.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

Slider

A value, or a range, on a track.

PropTypeDefaultDescription
labelReactNode—Visible label, wired to every thumb.
showValuebooleantrueShows the formatted value beside the label. On by default when there is a label.
thumbLabelsreadonly string[]—Names each thumb of a range for a screen reader: ["Minimum price", "Maximum price"].
marksreadonly (number | SliderMark)[][]Ticks on the track. A bare number draws a tick; an object with a label also prints it under the track and makes it a shortcut to that value.
startReactNode—Content beside the track — a speaker icon, a mute button.
endReactNode—Content on the other side of the track.
formatValue(value: number) => string—Formats the readout, the thumb bubble and what a screen reader announces.

Also takes every prop of Base UI Slider.Root.

Accessibility

  • Each thumb is a native input[type=range], so the platform's own slider semantics apply: arrows, Page Up and Down, Home and End, and Shift for a coarse step.
  • formatValue drives both the readout and aria-valuetext, so a screen reader announces the same string the page shows — without it, style: "percent" would read 60 as 6,000%.
  • thumbLabels names each thumb of a range; without it the label names the group and the thumbs read as two unlabelled sliders.

Motion

  • The readout's digits roll like an odometer, so a one-step move moves one digit instead of repainting the number.
  • The bubbles rise while a thumb is hovered, focused or dragged, and both show together on a range so the pair reads at once.
  • The thumb lifts on the frame it is grabbed, so the feedback is instant; only the scale animates.
  • Reduced motion turns the roll into a cut and stops the bubble's entrance.

Responsive behaviour

  • The track takes the width it is given, with start and end in their own columns, so the control stays usable at 320px.