Slider
sliderA 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.
"use client";
import { Volume1, Volume2, VolumeX } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/forme/button/button";
import { NumberFlow } from "@/components/forme/number-flow/number-flow";
import { Slider } from "@/components/forme/slider/slider";
const MONEY = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
maximumFractionDigits: 0,
});
const percent = (value: number) => `${value}%`;
/** What each shortlisted studio actually quoted. A range over these is honest. */
const QUOTES = [
1400, 1850, 2200, 2400, 2650, 2900, 3100, 3300, 3450, 3700, 3900, 4200, 4400, 4600, 4750, 5100,
5400, 5600, 5900, 6300, 6500, 6800, 7200, 7400, 7900, 8300, 8600, 9100, 9400, 9800, 10500, 11800,
];
export function SliderDemo() {
// Each example owns its state, so dragging one slider re-renders only that one.
return (
<div className="flex w-full max-w-md flex-col gap-10">
<BudgetExample />
<VolumeExample />
<FrameRateExample />
<DeployWindowExample />
</div>
);
}
function BudgetExample() {
const [budget, setBudget] = useState<[number, number]>([2000, 8000]);
// The count moves with the range, which is the point of a slider over two
// number fields: the answer is in the same glance as the question.
const matches = QUOTES.filter((quote) => quote >= budget[0] && quote <= budget[1]).length;
return (
<section className="grid gap-3">
<Slider
label="Budget"
value={budget}
onValueChange={(next) => setBudget(next as [number, number])}
min={0}
max={12000}
step={100}
minStepsBetweenValues={5}
thumbLabels={["Minimum budget", "Maximum budget"]}
formatValue={(value) => MONEY.format(value)}
/>
<p className="flex items-baseline gap-1 text-caption-1-regular text-muted-foreground">
<NumberFlow value={matches} className="text-body-2-medium text-foreground" duration={240} />
of {QUOTES.length} shortlisted studios quote in this range
</p>
</section>
);
}
function VolumeExample() {
const [volume, setVolume] = useState(60);
const [lastVolume, setLastVolume] = useState(60);
const muted = volume === 0;
const VolumeIcon = muted ? VolumeX : volume < 50 ? Volume1 : Volume2;
// Each label is a preset: pressing 50% moves the thumb there, and the one the
// slider is sitting on is marked as pressed. The icon swaps on mute.
return (
<section className="grid gap-3">
<Slider
label="Volume"
value={volume}
onValueChange={(next) => setVolume(next as number)}
max={100}
step={5}
formatValue={percent}
marks={[
{ value: 0, label: "0%" },
{ value: 25, label: "25%" },
{ value: 50, label: "50%" },
{ value: 75, label: "75%" },
{ value: 100, label: "100%" },
]}
start={
<Button
variant="ghost"
iconOnly
aria-label={muted ? "Unmute" : "Mute"}
aria-pressed={muted}
onClick={() => {
if (muted) {
setVolume(lastVolume || 50);
} else {
setLastVolume(volume);
setVolume(0);
}
}}
leadingIcon={VolumeIcon}
/>
}
/>
<p className="text-caption-1-regular text-muted-foreground">
Press a label to jump to it. The readout rolls one digit at a time.
</p>
</section>
);
}
function FrameRateExample() {
return (
<section className="grid gap-3">
<Slider
label="Frame rate"
defaultValue={30}
max={60}
step={1}
marks={[0, 15, 30, 45, 60]}
formatValue={(value) => `${value} fps`}
/>
<p className="text-caption-1-regular text-muted-foreground">
A bare number draws a tick and leaves the scale unlabelled; every tick pales once the fill
passes it.
</p>
</section>
);
}
function DeployWindowExample() {
return (
<section className="grid gap-3">
<Slider
label="Deploy window"
defaultValue={[9, 17]}
max={24}
step={1}
formatValue={(value) => `${String(value).padStart(2, "0")}:00`}
disabled
/>
<p className="text-caption-1-regular text-muted-foreground">
Locked while a release is in progress.
</p>
</section>
);
}Install
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.
markswhen 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.startorendfor 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
SegmentedControlnames each one and needs no dragging. - Anything where being off by a step changes meaning, unless
stepis 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.
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | — | Visible label, wired to every thumb. |
showValue | boolean | true | Shows the formatted value beside the label. On by default when there is a label. |
thumbLabels | readonly string[] | — | Names each thumb of a range for a screen reader: ["Minimum price", "Maximum price"]. |
marks | readonly (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. |
start | ReactNode | — | Content beside the track — a speaker icon, a mute button. |
end | ReactNode | — | 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. formatValuedrives both the readout andaria-valuetext, so a screen reader announces the same string the page shows — without it,style: "percent"would read 60 as 6,000%.thumbLabelsnames 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
startandendin their own columns, so the control stays usable at 320px.
Related


Checkbox
A single choice with a visible label wired to it for a screen reader. An indeterminate state for a select-all with only some rows picked, a description read as a description rather than folded into the name, a destructive variant, and a mark that draws itself in.
formsCombobox
A text field that filters a list as you type, with one value chosen from the results. Composable parts, so the field can hold a plain value, an object with a label, or several of either. Filtering, keyboard navigation and the active option being announced all come from Base UI.
forms

Poll
A question to vote on that turns into its results in place: bars grow to each share, the percentages roll and always total 100, and your choice is marked. Single or multiple choice, on real radios and checkboxes.
forms