Skip to content

Slider

  • Volume, brightness, zoom
  • Values where the rough position matters more than the exact number

Not for a range from–to, such as a price filter — use a RangeSlider.

Not when the exact value matters — use an Input with type="number".

Choosing between choosing one option or a value:

ComponentUse it forFor example
RadioGroupUp to about five options, all visible at once, as a form valueShipping speed, plan size
SelectOne option from a longer list, in little space, with the system pickerCountry, time zone, sort order in a form
ComboboxA long list people search by typing, several picks, or options loaded from a serverAssign reviewers, search a city, add tags
ToggleGroupA few options shown as buttons that apply at once, not a form fieldText alignment, list or grid view
SliderA number in a range, where dragging is easier than typing an exact valueVolume, brightness
RangeSliderA from–to range on one trackPrice filter, salary band
import { useState } from 'react';
import { Slider } from '@arun-dev/ui';
const field = { display: 'grid', gap: 'var(--space-3xs)', maxInlineSize: '20rem' };
export default function SliderBasics() {
const [volume, setVolume] = useState(40);
return (
<div style={{ display: 'grid', gap: 'var(--space-md)' }}>
<div style={field}>
<label htmlFor="slider-volume">
Volume <output htmlFor="slider-volume">{volume}</output>
</label>
<Slider
id="slider-volume"
name="volume"
min={0}
max={100}
step={5}
value={volume}
onChange={(event) => setVolume(Number(event.target.value))}
/>
</div>
<div style={field}>
<label htmlFor="slider-disabled">Disabled</label>
<Slider id="slider-disabled" defaultValue={60} disabled />
</div>
</div>
);
}

Slider is a native <input type="range">. The arrow keys, Page Up and Down, Home and End, step, the form value and form.reset() are all the browser’s, and react-hook-form’s register() binds it.

The browser draws it, in the brand’s accent colour (accent-color), with the track filled up to the thumb. Show the value yourself if it matters, such as with an <output> beside the label.

Slider props
PropTypeDefaultDescription
minnumber0The bottom of the range.
maxnumber100The top of the range.
stepnumber | 'any'1The increment the keys and the thumb move by.
classNamestringConcatenated with the component's own classes, never replacing them.
renderReactElementElement or component to render instead of the default. Props, className, event handlers and ref are merged onto it.
refRef<HTMLElement>Ref to the rendered element. Merged with any ref on the render element.
…restHTMLAttributesAnything else is spread onto the rendered element, so id, aria-*, data-* and event handlers all reach the DOM.
  • One thumb only. For a range from–to, use a RangeSlider.
  • The track and thumb shape are the browser’s. Only the colour is themed, through --slider-accent-color.