Skip to content

Range Slider

20 – 80
30° – 70°
2 – 4
30 – 70
20 – 80

A two-thumb slider built on two native <input type="range"> elements sharing one track — each thumb keeps the browser’s own slider role, keyboard control, pointer drag and form participation.

A separate component from Slider, not a mode on it: the value is a pair, and every operation (the clamp, the dependent bound, reporting) works on the pair as a whole.

<script>
import RangeSlider from "@invisible-ui/svelte/RangeSlider.svelte";
</script>

In Elements, value holds the pair as lower,upper, and lower-label and upper-label name the thumbs. Moving a thumb sends a bubbling change event with the complete pair in detail.value:

<ds-range-slider
label="Price"
lower-label="Minimum price"
upper-label="Maximum price"
name="price"
value="20,80"
></ds-range-slider>
PropTypeDefaultDescription
valuereadonly [number, number][0, 100]
minnumber0
maxnumber100
stepnumber1
minDistancenumber0The gap the two thumbs may not close. They may touch; they never cross.
orientation"horizontal" | "vertical""horizontal"
disabledbooleanfalse
label *string—Accessible name for the group.
thumbLabels *readonly [string, string]—Accessible name for each thumb: [lowerLabel, upperLabel].
errorstring | undefinedundefinedError message, shown under the track and announced. Both inputs point at it through aria-describedby and take aria-invalid. The app owns it: a form reset leaves it in place, so the app clears it.
namestring | undefinedundefinedForm field name — both thumbs submit under it, in order: FormData.getAll(name) reads [String(lower), String(upper)].
showValuebooleanfalseShow the current values to the side of the track.
showRangebooleanfalseShow the min and max reference values under the ends of the track.
ticksbooleanfalseShow tick marks at each step (only when the count is reasonable).
format(value: number) => string(v) => String(v)Format a displayed value (e.g. add a unit).
onValueChange((value: readonly [number, number]) => void) | undefinedundefinedCalled with the complete pair whenever it changes.
iconSnippet | undefinedundefinedA decorative icon before the track.
  • The thumbs never cross. Dragging one past the other clamps it at the other’s value (minus minDistance, when given) instead of swapping which thumb is which. DOM order, tab order and thumb identity never change, even when both values are equal.
  • One action reports the complete pair, once. onValueChange receives [lower, upper]; reflecting a controlled value prop back reports nothing, and neither does a native form reset.
  • minDistance rounds up to the step grid and is capped at the span. A distance the grid cannot express is taken as the next reachable one, never a smaller one, so the pair is never closer than was asked; a distance wider than the track leaves exactly one legal pair, [min, max]. A clamped value always lands on a value the user could have reached themselves.
  • Constraints may change after mount. min, max, step, minDistance, orientation and disabled reach the control without a remount. A pair the new constraints no longer allow is normalized silently, and the form-reset default with it; nothing is reported.
  • Pointer presses reach the nearer thumb, along the logical axis. Two overlapping range inputs hit-test by stacking order, so the thumb nearer the pointer is raised before the press lands, in horizontal LTR, horizontal RTL and vertical alike. A drag already in progress is never interrupted.
  • Stacked thumbs stay operable without a hover. When both thumbs sit on the same value, a pointer to one side of the stack reaches the thumb that would move that way. With no pointer over the track at all, as with a touch, the upper thumb is on top unless the pair is stacked at max, where only the lower one can move; the other thumb is reached by moving the top one off it first.
20 – 90

A non-empty error shows the message under the control with a hazard icon and announces it as an alert. Both inputs point at it through aria-describedby and take aria-invalid="true". The group around them takes neither. The message is plain text.

<RangeSlider
label="Ticket price"
thumbLabels={["Lowest ticket price", "Highest ticket price"]}
bind:value={ticketPrice}
error={ticketPrice[1] > 80 ? "The highest ticket price is 80." : ""}
/>

The app owns the message and clears it: a form reset leaves it in place. In Flutter, the validator’s message clears on form reset.

  • Two native <input type="range"> elements: the browser provides each thumb’s slider role, ARIA value, Arrow / Home / End / PageUp / PageDown control, pointer dragging and form submission.
  • label names the group; thumbLabels names each thumb, because there is no universal wording for “the lower one” to fall back to.
  • Each thumb reports the bound it may not cross in two ways. An explicit aria-valuemin / aria-valuemax override carries it as numbers; ARIA in HTML discourages this override on a native range input, and the attributes being present is not proof that every accessibility tree or assistive technology honours them over the input’s own min and max. aria-valuetext therefore carries the same constraint as text: it is permitted on a native range input, so it does not depend on the override being honoured, though what an engine exposes is still the engine’s. WAI-ARIA supplies the normative role and state requirements here; the Authoring Practices supply the pattern guidance.
  • What real assistive technology announces, and how touch assistive technology reaches stacked thumbs, are not verified by the automated suites: that validation belongs to the final manual accessibility session (A1).
  • The thumb is 24 × 24 CSS pixels by default, the smallest pointer target WCAG 2.2 accepts.
  • A non-empty error adds aria-invalid="true" and an aria-describedby link to the message on both inputs.

Both thumbs submit under the same name, in order:

new FormData(form).getAll("price"); // ["20", "80"]

A native reset restores the current default pair and reports nothing through onValueChange; in Vue the v-model binding follows the reset, as it does for Slider.

<RangeSlider
value={[20, 80]}
min={0}
max={100}
step={5}
minDistance={10}
label="Price range"
thumbLabels={["Minimum price", "Maximum price"]}
showValue
showRange
/>

In React, the value is a pair and onValueChange reports the whole pair:

<RangeSlider
label="Price range"
thumbLabels={["Minimum price", "Maximum price"]}
value={range}
minDistance={10}
onValueChange={setRange}
/>

Themeable via --ds-range-slider-* (length for the horizontal width, vertical-length for the upright track, track-size, thumb-size).