Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Forms

Slider

Free3.5 KB gzipped

Pick 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

tsx
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%

tsx
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.

tsx
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.

tsx
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.

tsx
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.

tsx
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

Slider props
PropTypeDefault
value

Controlled value. A number for one thumb, or [start, end] for a range.

SliderValue—
defaultValue

Initial value when uncontrolled. Pass a [start, end] pair for a range. Defaults to min.

SliderValue—
onValueChange

Called with the next value on every change (drag, click, key press).

(value: T) => void—
onValueCommit

Called once an interaction ends: on pointer up and on key up. Use it for expensive work (fetching, saving).

(value: T) => void—
min

Lowest value. Default 0.

number—
max

Highest value. Default 100.

number—
step

Granularity of the value. Every value snaps to min + n * step. Default 1.

number—
largeStep

Jump used by PageUp / PageDown and Shift + Arrow. Defaults to 10 * step.

number—
orientation

Horizontal (default) or vertical. A vertical slider fills its height; give it one with style or a parent (default 12rem).

"horizontal""vertical"—
size

Track thickness and thumb size. Every size keeps a 24px pointer target. Default md (or the Field's size).

"sm""md""lg"—
tone

Semantic color of the fill and thumb border. Default primary. Ignored while invalid (danger is used).

"neutral""primary""accent""success""warning""danger""info"—
disabled

Disables every thumb. Picked up from a surrounding Field.

boolean—
readOnly

Thumbs stay focusable and announce their value, but the value can't change.

boolean—
invalid

Marks the slider invalid: danger styling and aria-invalid. Picked up from a surrounding Field.

boolean—
inverted

Flips the direction: max sits at the inline start (horizontal) or the bottom (vertical). Arrow keys follow what you see.

boolean—
minStepsBetweenThumbs

Range only: the minimum number of steps kept between the two thumbs. Default 0 (thumbs may meet but never cross).

number—
marks

Ticks under the track: true for one per step, or a list of { value, label? }.

boolean | SliderMark[]—
showValue

When to show the value bubble above each thumb. Default never.

"never""hover""always"—
formatValue

Formats a value for the bubble and for aria-valuetext (e.g. currency or percent).

(value: number) => string—
getAriaValueText

Custom aria-valuetext per thumb. Wins over formatValue for assistive tech.

(value: number, thumbIndex: number) => string—
name

Form field name. Renders one <input type="hidden"> per thumb (a range submits the name twice; read it with FormData.getAll).

string—
thumbLabels

Accessible names for each thumb, e.g. ["Minimum price", "Maximum price"]. Recommended for ranges.

string[]—
aria-label

Accessible name for the thumb(s) when there is no visible label. Applied to the thumbs, not the wrapper.

string—
aria-labelledby

id(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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

36 passed · 0 failed · 29 not applicable · 10 to check by hand

Dark mode

Score 100

36 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

Keyboard
KeyAction
Arrow RightArrow UpIncreases by step (Shift: large step). Mirrored right to left.
Arrow LeftArrow DownDecreases by step (Shift: large step).
Page UpPage DownIncreases or decreases by the large step.
HomeEndGoes to the minimum or maximum.
EscapeHides 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

Roles and states
ElementRoleStates and properties
Thumbslideraria-valuenow, aria-valuemin, aria-valuemax, aria-valuetext, aria-orientation
Range slidergrouparia-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.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)