Introducing PrimeReact v11-alpha 🎉Discover Now

Slider

An unstyled, accessible slider component with compound composition.

Build fully custom sliders and range inputs with complete control over track, range, and thumb rendering.

basic-demo

Pre-styled Versions

Choose a pre-styled library to use Slider with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with four sub-components: Root, Track, Range, Thumb
  • Single value and range mode with multiple thumbs
  • Horizontal and vertical orientation
  • Configurable step size and minimum thumb distance

Usage#

import { Slider } from 'primereact/slider';
<Slider.Root>
    <Slider.Track>
        <Slider.Range />
    </Slider.Track>
    <Slider.Thumb />
</Slider.Root>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Slider.Root as="div">
    <Slider.Track as="div">
        <Slider.Range as="div" />
    </Slider.Track>
    <Slider.Thumb as="div" />
</Slider.Root>

Default elements: Root=span, Track=span, Range=span, Thumb=span.

Render Function Children#

Thumb accepts a render function as children, providing access to the component instance. The instance exposes slider (root instance with state.value and state.isDragging).

<Slider.Thumb>{(instance) => <span>{instance.slider?.getThumbValue(0)}</span>}</Slider.Thumb>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

SliderRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: SliderRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: SliderRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceSliderRootInstance—
The instance to pass to the component.
ptSafeRecord<SliderRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: SliderRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
valuenumber | number[]—
Value of the component.
defaultValuenumber | number[]—
The default value for the input when not controlled by `value` .
minnumber0
Mininum boundary value.
maxnumber100
Maximum boundary value.
orientation"horizontal" | "vertical"horizontal
Orientation of the slider.
stepnumber1
Step factor to increment/decrement the value.
minStepsBetweenThumbsnumber0
Minimum steps between thumbs.
readOnlybooleanfalse
Whether the component is read-only.
invalidbooleanfalse
When present, it specifies that the element should be invalid.
onFocus(event: FocusEvent<HTMLInputElement>) => void—
Callback to invoke when a thumb input receives focus.
onBlur(event: FocusEvent<HTMLInputElement>) => void—
Callback to invoke when a thumb input loses focus.
disabledbooleanfalse
When present, it specifies that the element should be disabled.
onValueChange(event: SliderRootChangeEvent) => void—
Callback fired when the ToggleButton's pressed state changes.
onValueChangeEnd(event: SliderRootChangeEvent) => void—
Callback fired when the pointer interaction ends.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-orientation"horizontal" or "vertical"
data-disabledPresent when disabled
data-draggingPresent when dragging

Defines passthrough(pt) options of Slider component.

labeltypedescription
rootSliderRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
rangeSliderRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the range's DOM element.
thumbSliderRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the thumb's DOM element.

SliderTrack#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: SliderTrackInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: SliderTrackInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceSliderTrackInstance—
The instance to pass to the component.
ptSafeRecord<SliderTrackPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: SliderTrackInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-orientation"horizontal" or "vertical"
data-disabledPresent when disabled
data-draggingPresent when dragging

Defines passthrough(pt) options of SliderTrack component.

labeltypedescription
rootSliderTrackPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

SliderRange#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: SliderRangeInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: SliderRangeInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceSliderRangeInstance—
The instance to pass to the component.
ptSafeRecord<SliderRangePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: SliderRangeInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-orientation"horizontal" or "vertical"
data-disabledPresent when disabled
data-draggingPresent when dragging

Defines passthrough(pt) options of SliderRange component.

labeltypedescription
rootSliderRangePassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

SliderThumb#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: SliderThumbInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: SliderThumbInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceSliderThumbInstance—
The instance to pass to the component.
ptSafeRecord<SliderThumbPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: SliderThumbInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
indexnumber0
Index of the thumb.
tabIndexnumber0
Index of the element in tabbing order.
ariaLabelstring—
Establishes a string value that labels the component.
ariaLabelledbystring—
Establishes relationships between the component and label(s) where its value should be one or more element IDs.
namestring—
Name attribute of the input.
inputIdstring—
Id of the input.
inputStyleCSSProperties—
Style of the input element.
inputClassNamestring—
Style class of the input element.
disabledbooleanfalse
When present, it specifies that the element should be disabled.
readOnlybooleanfalse
When present, it specifies that the element should be read-only.
invalidbooleanfalse
When present, it specifies that the element is invalid.
requiredboolean—
When present, it specifies that the element is required.
onFocusFocusEventHandler<HTMLInputElement>—
Callback fired on focus.
onBlurFocusEventHandler<HTMLInputElement>—
Callback fired on blur.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-indexThumb index number
data-orientation"horizontal" or "vertical"
data-disabledPresent when disabled
data-draggingPresent when dragging

Defines passthrough(pt) options of SliderThumb component.

labeltypedescription
rootSliderThumbPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

Slider component uses a native range input internally with slider role. The input includes aria-orientation, aria-valuemin, aria-valuemax, and aria-valuenow attributes. Value to describe the component can be defined using aria-labelledby and aria-label props on Thumb.

<span id="slider_label">Volume</span>
<Slider.Root>
    <Slider.Track>
        <Slider.Range />
    </Slider.Track>
    <Slider.Thumb aria-labelledby="slider_label" />
</Slider.Root>
 
<Slider.Root>
    <Slider.Track>
        <Slider.Range />
    </Slider.Track>
    <Slider.Thumb aria-label="Volume" />
</Slider.Root>

Keyboard Support#

KeyFunction
tabMoves focus to the slider.
left arrow / up arrowDecrements the value.
right arrow / down arrowIncrements the value.
homeSet the minimum value.
endSet the maximum value.
page upIncrements the value by 10 steps.
page downDecrements the value by 10 steps.