Forms
Slider
Free3.5 KB gzippedPick a number, or a [start, end] range, on a pill track. Follows the WAI-ARIA APG Slider and Multi-Thumb Slider patterns: every thumb is a focusable role="slider" with aria-valuemin/max/now/text.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Arrow Right, Arrow Up, Arrow Left and 6 more · Full report
Import
import { Slider } from "@vjdesigns/vjdesigns-ui";
Importing only Slider adds about 3.5 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
40%
import { useState } from "react";
import { Field, Slider, Stack, Text } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
const [volume, setVolume] = useState(40);
return (
<Stack gap={2} style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Volume">
<Slider value={volume} onValueChange={setVolume} />
</Field>
<Text size="sm" tone="muted">
{volume}%
</Text>
</Stack>
);
}
Range
Pass an array to get one thumb per value. Each thumb gets its own accessible label.
import { Field, Slider } from "@vjdesigns/vjdesigns-ui";
export function Range() {
return (
<div style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Price range">
<Slider
defaultValue={[200, 800]}
min={0}
max={1000}
step={50}
minStepsBetweenThumbs={2}
thumbLabels={["Minimum price", "Maximum price"]}
formatValue={(value) => `${value}`}
showValue="always"
/>
</Field>
</div>
);
}
Marks
marks labels points along the track.
import { Field, Slider } from "@vjdesigns/vjdesigns-ui";
export function Marks() {
return (
<div style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Team size">
<Slider
defaultValue={10}
min={1}
max={50}
marks={[
{ value: 1, label: "1" },
{ value: 10, label: "10" },
{ value: 25, label: "25" },
{ value: 50, label: "50" },
]}
tone="success"
/>
</Field>
</div>
);
}
Accessibility
Every thumb needs a name: thumbLabels names each end of a range, and formatValue makes screen readers say "$40" instead of "40" through aria-valuetext. Arrow keys move by step, Page Up and Page Down by largeStep, Home and End jump to the limits.
import { useState } from "react";
import { Field, Slider } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
const [range, setRange] = useState<[number, number]>([40, 160]);
return (
<div style={{ width: "100%", maxWidth: "24rem" }}>
<Field label="Price range">
<Slider
value={range}
onValueChange={(value) => setRange(value as [number, number])}
min={0}
max={300}
step={5}
largeStep={50}
thumbLabels={["Minimum price", "Maximum price"]}
formatValue={(value) => `${value}`}
showValue="always"
/>
</Field>
</div>
);
}
Translated
In Arabic the track runs right to left: the minimum is on the right, and the arrow keys follow the reading direction. Format numbers for the locale with Intl.NumberFormat.
import { Field, Slider, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
export function Translated() {
const percent = new Intl.NumberFormat("ar", { style: "percent" });
return (
<LocaleProvider locale="ar" messages={ar}>
<div style={{ width: "100%", maxWidth: "24rem" }}>
<Field label="مستوى الصوت">
<Slider defaultValue={30} showValue="always" formatValue={(value) => percent.format(value / 100)} />
</Field>
</div>
</LocaleProvider>
);
}
Usage notes
Operable without dragging (WCAG 2.5.7): click or tap anywhere on the track to move the nearest thumb there, or use the keyboard (Arrows, PageUp / PageDown, Home / End). Dragging with a mouse, pen, or finger also works.
Inside a Field, the Field's label names the thumb, and its hint, error, invalid, and disabled state are wired automatically.
API reference
Slider
| Prop | Type | Default |
|---|---|---|
valueControlled value. A number for one thumb, or | SliderValue | — |
defaultValueInitial value when uncontrolled. Pass a | SliderValue | — |
onValueChangeCalled with the next value on every change (drag, click, key press). | (value: T) => void | — |
onValueCommitCalled once an interaction ends: on pointer up and on key up. Use it for expensive work (fetching, saving). | (value: T) => void | — |
minLowest value. Default | number | — |
maxHighest value. Default | number | — |
stepGranularity of the value. Every value snaps to | number | — |
largeStepJump used by PageUp / PageDown and Shift + Arrow. Defaults to | number | — |
orientationHorizontal (default) or vertical. A vertical slider fills its height; give it one with | "horizontal""vertical" | — |
sizeTrack thickness and thumb size. Every size keeps a 24px pointer target. Default | "sm""md""lg" | — |
toneSemantic color of the fill and thumb border. Default | "neutral""primary""accent""success""warning""danger""info" | — |
disabledDisables every thumb. Picked up from a surrounding Field. | boolean | — |
readOnlyThumbs stay focusable and announce their value, but the value can't change. | boolean | — |
invalidMarks the slider invalid: danger styling and | boolean | — |
invertedFlips the direction: max sits at the inline start (horizontal) or the bottom (vertical). Arrow keys follow what you see. | boolean | — |
minStepsBetweenThumbsRange only: the minimum number of steps kept between the two thumbs. Default | number | — |
marksTicks under the track: | boolean | SliderMark[] | — |
showValueWhen to show the value bubble above each thumb. Default | "never""hover""always" | — |
formatValueFormats a value for the bubble and for | (value: number) => string | — |
getAriaValueTextCustom | (value: number, thumbIndex: number) => string | — |
nameForm field name. Renders one | string | — |
thumbLabelsAccessible names for each thumb, e.g. | string[] | — |
aria-labelAccessible name for the thumb(s) when there is no visible label. Applied to the thumbs, not the wrapper. | string | — |
aria-labelledbyid(s) of the visible label. Applied to the thumbs (and the range group). Inside a Field, the Field's label is used. | string | — |
Also accepts native <div> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Slider targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Dark mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Arrow RightArrow Up | Increases by step (Shift: large step). Mirrored right to left. |
| Arrow LeftArrow Down | Decreases by step (Shift: large step). |
| Page UpPage Down | Increases or decreases by the large step. |
| HomeEnd | Goes to the minimum or maximum. |
| Escape | Hides the value bubble (showValue="hover"). |
Each thumb is a tab stop. Clicking the track also moves the nearest thumb, so dragging is never required (WCAG 2.5.7).
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Thumb | slider | aria-valuenow, aria-valuemin, aria-valuemax, aria-valuetext, aria-orientation |
| Range slider | group | aria-labelledby; each thumb named ("Minimum", "Maximum") |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |