Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Slider

A slider selects a value, or a range of values, by dragging a thumb along a track. Arrow keys nudge the value and Home/End jump to the bounds, so the control is fully operable without a pointer.

The component is composed from parts. <Slider> owns the state machine; the remaining parts read it from context, so they must all be rendered inside <Slider>.

React Sliderlive
import {
Slider, SliderLabel, SliderControl, SliderTrack, SliderRange, SliderThumb,
} from "@/components/ui/slider";
export function VolumeSlider() {
return (
<Slider defaultValue={[40]} min={0} max={100} step={5}>
<SliderLabel>Volume</SliderLabel>
<SliderControl>
<SliderTrack>
<SliderRange />
</SliderTrack>
<SliderThumb index={0} />
</SliderControl>
</Slider>
);
}
Terminal window
npx @glaceon/cli add slider --framework react # or svelte, solid
Attribute Values Applied to
data-scope slider every part
data-part root, label, control, track, range, thumb matching part
data-dragging present / absent thumb
data-disabled present / absent root, control, track, range, thumb
data-orientation horizontal, vertical root and below

The thumb element is a 44px hit area wrapping a 20px visual dot. Style the dot, not the thumb: giving the thumb a background shrinks the target to the visual size. The same applies to the control, which is a 44px lane that the finger lands on.

Part Prop Type Description
Slider children content The root and its control
Slider defaultValue number[] Initial value
Slider value number[] Controlled value
Slider min / max number Bounds
Slider step number Increment per step
Slider disabled boolean Prevents interaction
Slider name string Name used in form submission
Slider onValueChange (details) => void Called as the value changes
SliderThumb index number Which thumb, for a range slider. Defaults to 0

Multiple thumbs work by rendering one <SliderThumb> per index under the same <SliderTrack>. Every part also accepts className (React) or class (Svelte, Solid), merged with cn().

Key Behaviour
Arrow Right / Arrow Up Increases the value by one step
Arrow Left / Arrow Down Decreases the value by one step
Home Jumps to the minimum
End Jumps to the maximum

role="slider", aria-valuenow, aria-valuemin, aria-valuemax and aria-orientation are managed by the Zag.js machine. The 44px hit area satisfies WCAG 2.2 SC 2.5.8 target size requirements.