Skip to content

Range Slider

Edit on GitHub

Select a value or a range of values using a draggable slider.

@volvo-cars/css v2.5.1@volvo-cars/react-forms v2.0.1

A simple range slider with controlled value.

Show codeHide code
import { RangeSlider } from '@volvo-cars/react-forms';
import { useState } from 'react';
export function RangeSliderBasic() {
const [value, setValue] = useState(50);
return (
<div className="my-24">
<RangeSlider
value={value}
onChange={(e) => setValue(Number(e.target.value))}
/>
</div>
);
}

Enable the tooltip prop to show the current value while dragging.

Pair the slider with a label and <output> element to display the current value prominently.

The DoubleRangeSlider renders two thumbs for selecting a min/max range. It wraps two native <input type="range"> elements inside a role="group" container.

Show codeHide code
import { DoubleRangeSlider } from '@volvo-cars/react-forms';
import { useState } from 'react';
export function DoubleRangeSliderBasic() {
const [value, setValue] = useState<[number, number]>([25, 75]);
return (
<div className="my-24">
<DoubleRangeSlider
value={value}
onValueChange={setValue}
minLabel="Minimum value"
maxLabel="Maximum value"
aria-label="Range"
/>
</div>
);
}

The value and defaultValue props accept a [number, number] tuple. Use onValueChange to receive the updated [min, max] pair directly, or onChange for the native input event.

Enable the tooltip prop to show the current value for each thumb while it is dragged.

Use aria-labelledby on the DoubleRangeSlider to reference a visible <label>. Customise minLabel and maxLabel to give each thumb a meaningful accessible name (defaults are “Minimum value” and “Maximum value”).

The RangeSlider can be used in two modes:

  • Controlled: Set both value and onChange props to manage the value externally
  • Uncontrolled: Use defaultValue for initial value, let the component manage state internally
// Controlled
<RangeSlider value={value} onChange={(e) => setValue(Number(e.target.value))} />
// Uncontrolled
<RangeSlider defaultValue={50} />

The same pattern applies to DoubleRangeSlider, where value and defaultValue accept a [number, number] tuple.

  • Use a <label> element linked via htmlFor matching the slider’s id
  • Use <output> element with htmlFor to announce value changes to screen readers
  • Arrow keys adjust the value when the slider is focused
  • The thumb has a minimum touch target of 40×40 pixels

Range slider target size

For the DoubleRangeSlider:

  • The component renders a role="group" container. Label it with aria-labelledby or aria-label
  • Each thumb has its own accessible name via minLabel and maxLabel: always customise these to match the context (e.g. “Minimum price”, “Maximum price”)
  • When tooltip is enabled, <output> elements with aria-live="polite" announce value changes

See the full accessibility documentation for WCAG 2.2 criteria details.

Range slider keyboard input

KeyAction
Arrow RightIncrease value by step
Arrow LeftDecrease value by step
Arrow UpIncrease value by step
Arrow DownDecrease value by step
HomeSet to minimum value
EndSet to maximum value
TabMove focus between thumbs (DoubleRangeSlider)
PropTypeRequiredDefault
namestring--
The name of the input to use when submitting the form.
formstring--
Id of a form element that this input should be associated with. Defaults to the containing form element.
onFocusFocusEventHandler<HTMLInputElement>--
onBlurFocusEventHandler<HTMLInputElement>--
onKeyDownKeyboardEventHandler<HTMLInputElement>--
onKeyUpKeyboardEventHandler<HTMLInputElement>--
minnumber-0
The minimum value for the input.
maxnumber-100
The maximum value for the input.
stepnumber--
The step interval between values.
liststring--
Id of a `<datalist>` element with a list of predefined values to suggest to the user.
defaultValuenumber--
Default value of an uncontrolled input.
tooltipboolean-false
Provide a tooltip while sliding, indicating the current value.
valuenumber--
Value of the input. Makes the input controlled.
onChangeChangeEventHandler<HTMLInputElement, Element>--
Fires immediately when the input’s value is changed by the user (for example, it fires on every keystroke).
hiddenboolean--
idstring--
titlestring--
dirstring--
langstring--
slotstring--
translate"yes" | "no"--
classNamestring--
styleCSSProperties--
tabIndexnumber--
onPointerDownPointerEventHandler<Element>--
onPointerEnterPointerEventHandler<Element>--
onPointerLeavePointerEventHandler<Element>--
onPointerMovePointerEventHandler<Element>--
onPointerUpPointerEventHandler<Element>--
PropTypeRequiredDefault
namestring--
The name of the input to use when submitting the form.
formstring--
Id of a form element that this input should be associated with. Defaults to the containing form element.
onFocusFocusEventHandler<HTMLInputElement>--
onBlurFocusEventHandler<HTMLInputElement>--
onKeyDownKeyboardEventHandler<HTMLInputElement>--
onKeyUpKeyboardEventHandler<HTMLInputElement>--
minnumber-0
The minimum value for the input.
maxnumber-100
The maximum value for the input.
stepnumber-1
The step interval between values.
liststring--
Id of a `<datalist>` element with a list of predefined values to suggest to the user.
defaultValue[number, number]--
Default value of an uncontrolled input.
precisionnumber--
Number of decimal places to round values to.
tooltipboolean-false
Provide a tooltip while sliding, indicating the current value.
value[number, number]--
Value of the input. Makes the input controlled.
onChangeChangeEventHandler<HTMLInputElement, Element>--
Native change event handler, passed through as-is from whichever input fired. Use this when you need access to the underlying DOM event (e.g. to inspect `event.target.name` or integrate with form libraries).
onValueChange((values: [number, number]) => void)--
Fires immediately when either slider's value changes. Provides the full numeric pair `[min, max]` as the primary payload so consumers can keep the range value in state without parsing native events.
minLabelstring-Minimum value
Accessible label for the minimum value input.
maxLabelstring-Maximum value
Accessible label for the maximum value input.
aria-labelledbystring--
ID of an element that labels the slider group.
aria-labelstring--
Accessible label for the slider group.
hiddenboolean--
idstring--
titlestring--
dirstring--
langstring--
slotstring--
translate"yes" | "no"--
classNamestring--
styleCSSProperties--
tabIndexnumber--
onPointerDownPointerEventHandler<Element>--
onPointerEnterPointerEventHandler<Element>--
onPointerLeavePointerEventHandler<Element>--
onPointerMovePointerEventHandler<Element>--
onPointerUpPointerEventHandler<Element>--