Slider
An easily stylable range input.
View as MarkdownUsage guidelines
- Form controls must have an accessible name: Prefer
<Slider.Label>, or provide anaria-labelon each<Slider.Thumb>when no visible label is rendered. See Labeling a slider and the forms guide.
Anatomy
Import the component and assemble its parts:
Examples
Range slider
To create a range slider:
- Pass an array of values and place a
<Slider.Thumb>for each value in the array - Additionally for server-side rendering, specify a numeric
indexfor each thumb that corresponds to the index of its value in the value array
Thumbs can be configured to behave differently when they collide during pointer interactions using the thumbCollisionBehavior prop on <Slider.Root>.
Thumb alignment
Set thumbAlignment="edge" to inset the thumb such that its edge aligns with the edge of the control when the value is at min or max, without overflowing the control like the default "center" alignment.
A client-only alternative thumbAlignment="edge-client-only" can be used to reduce bundle size but only renders after React hydration.
Labeling a slider
A single-thumb slider without a visible label (such as a volume control) can be labeled using aria-label on <Slider.Thumb>:
A visible label can be created using <Slider.Label>:
For a multi-thumb range slider with a visible label, add aria-label on each <Slider.Thumb> to distinguish them:
Vertical
Set orientation="vertical" on <Slider.Root> to build a vertical slider.
Form integration
To use a slider in a form, pass the slider name to <Slider.Root>:
For grouped multi-thumb range sliders in forms, Fieldset can provide the shared visible label while each thumb keeps its own aria-label:
API reference
Root
Groups all parts of the slider.
Renders a <div> element.
namestring—
- Name
- Description
Identifies the field when a form is submitted.
- Type
defaultValuenumber | number[]—
- Name
- Description
The uncontrolled value of the slider when it’s initially rendered.
To render a controlled slider, use the
valueprop instead.- Type
valuenumber | number[]—
- Name
- Description
The value of the slider. For ranged sliders, provide an array with two values.
- Type
onValueChangefunction—
- Name
- Description
Callback function that is fired when the slider’s value changed. You can pull out the new value by accessing
event.target.value(any).The
eventDetails.reasonindicates what triggered the change:'input-change'when the hidden range input emits a change event (for example, via form integration)'track-press'when the control track is pressed'drag'while dragging a thumb'keyboard'for keyboard input'none'when the change is triggered without a specific interaction
- Type
onValueCommittedfunction—
- Name
- Description
Callback function that is fired when the
pointerupis triggered. Warning: This is a generic event not a change event.The
eventDetails.reasonindicates what triggered the commit:'drag'while dragging a thumb'track-press'when the control track is pressed'keyboard'for keyboard input'input-change'when the hidden range input emits a change event (for example, via form integration)'none'when the commit occurs without a specific interaction
- Type
formstring—
- Name
- Description
Identifies the form that owns the slider inputs. Useful when the slider is rendered outside the form.
- Type
localeIntl.LocalesArgument—
- Name
- Description
The locale used by
Intl.NumberFormatwhen formatting the value. Defaults to the user’s runtime locale.- Type
thumbAlignmentUnion'center'
- Name
- Description
How the thumb(s) are aligned relative to
Slider.Controlwhen the value is atminormax:center: The center of the thumb is aligned with the control edgeedge: The thumb is inset within the control such that its edge is aligned with the control edgeedge-client-only: Same asedgebut renders after React hydration on the client, reducing bundle size in return
- Type
- Default
'center'
thumbCollisionBehaviorUnion'push'
- Description
Controls how thumbs behave when they collide during pointer interactions.
'push'(default): Thumbs push each other without restoring their previous positions when dragged back.'swap': Thumbs swap places when dragged past each other.'none': Thumbs cannot move past each other; excess movement is ignored.
- Type
- Default
'push'
stepnumber1
- Name
- Description
The granularity with which the slider can step through values. (A “discrete” slider.) The
minprop serves as the origin for the valid values. We recommend (max — min) to be evenly divisible by the step.- Type
- Default
1
largeStepnumber10
- Name
- Description
The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.
- Type
- Default
10
minStepsBetweenValuesnumber0
- Description
The minimum steps between values in a range slider.
- Type
- Default
0
minnumber0
- Name
- Description
The minimum allowed value of the slider. Should not be equal to max.
- Type
- Default
0
maxnumber100
- Name
- Description
The maximum allowed value of the slider. Should not be equal to min.
- Type
- Default
100
formatIntl.NumberFormatOptions—
- Name
- Description
Options to format the input value.
- Type
disabledbooleanfalse
- Name
- Description
Whether the slider should ignore user interaction.
- Type
- Default
false
orientationOrientation'horizontal'
- Name
- Description
The component orientation.
- Type
- Default
'horizontal'
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-dragging
Present while the user is dragging.
data-orientation
Indicates the orientation of the slider.
data-disabled
Present when the slider is disabled.
data-valid
Present when the slider is in valid state (when wrapped in Field.Root).
data-invalid
Present when the slider is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the slider’s value has changed (when wrapped in Field.Root).
data-touched
Present when the slider has been touched (when wrapped in Field.Root).
data-focused
Present when the slider is focused (when wrapped in Field.Root).
| Attribute | Description | |
|---|---|---|
data-dragging | Present while the user is dragging. | |
data-orientation | Indicates the orientation of the slider. | |
data-disabled | Present when the slider is disabled. | |
data-valid | Present when the slider is in valid state (when wrapped in Field.Root). | |
data-invalid | Present when the slider is in invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the slider’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the slider has been touched (when wrapped in Field.Root). | |
data-focused | Present when the slider is focused (when wrapped in Field.Root). | |
Slider.Root.StateHide
Slider.Root.ChangeEventReasonHide
Slider.Root.ChangeEventDetailsHide
Slider.Root.CommitEventReasonHide
Slider.Root.CommitEventDetailsHide
Label
An accessible label that is automatically associated with the slider thumbs.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
Slider.Label.StateHide
Value
Displays the current value of the slider as text.
Renders an <output> element.
children| ((formattedValues: string[], values: number[]) => React.ReactNode)
| null—
| null
- Name
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-dragging
Present while the user is dragging.
data-orientation
Indicates the orientation of the slider.
data-disabled
Present when the slider is disabled.
data-valid
Present when the slider is in valid state (when wrapped in Field.Root).
data-invalid
Present when the slider is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the slider’s value has changed (when wrapped in Field.Root).
data-touched
Present when the slider has been touched (when wrapped in Field.Root).
data-focused
Present when the slider is focused (when wrapped in Field.Root).
| Attribute | Description | |
|---|---|---|
data-dragging | Present while the user is dragging. | |
data-orientation | Indicates the orientation of the slider. | |
data-disabled | Present when the slider is disabled. | |
data-valid | Present when the slider is in valid state (when wrapped in Field.Root). | |
data-invalid | Present when the slider is in invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the slider’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the slider has been touched (when wrapped in Field.Root). | |
data-focused | Present when the slider is focused (when wrapped in Field.Root). | |
Slider.Value.StateHide
Control
The clickable, interactive part of the slider.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-dragging
Present while the user is dragging.
data-orientation
Indicates the orientation of the slider.
data-disabled
Present when the slider is disabled.
data-valid
Present when the slider is in valid state (when wrapped in Field.Root).
data-invalid
Present when the slider is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the slider’s value has changed (when wrapped in Field.Root).
data-touched
Present when the slider has been touched (when wrapped in Field.Root).
data-focused
Present when the slider is focused (when wrapped in Field.Root).
| Attribute | Description | |
|---|---|---|
data-dragging | Present while the user is dragging. | |
data-orientation | Indicates the orientation of the slider. | |
data-disabled | Present when the slider is disabled. | |
data-valid | Present when the slider is in valid state (when wrapped in Field.Root). | |
data-invalid | Present when the slider is in invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the slider’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the slider has been touched (when wrapped in Field.Root). | |
data-focused | Present when the slider is focused (when wrapped in Field.Root). | |
Slider.Control.StateHide
Track
Contains the slider indicator and represents the entire range of the slider.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-dragging
Present while the user is dragging.
data-orientation
Indicates the orientation of the slider.
data-disabled
Present when the slider is disabled.
data-valid
Present when the slider is in valid state (when wrapped in Field.Root).
data-invalid
Present when the slider is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the slider’s value has changed (when wrapped in Field.Root).
data-touched
Present when the slider has been touched (when wrapped in Field.Root).
data-focused
Present when the slider is focused (when wrapped in Field.Root).
| Attribute | Description | |
|---|---|---|
data-dragging | Present while the user is dragging. | |
data-orientation | Indicates the orientation of the slider. | |
data-disabled | Present when the slider is disabled. | |
data-valid | Present when the slider is in valid state (when wrapped in Field.Root). | |
data-invalid | Present when the slider is in invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the slider’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the slider has been touched (when wrapped in Field.Root). | |
data-focused | Present when the slider is focused (when wrapped in Field.Root). | |
Slider.Track.StateHide
Indicator
Visualizes the current value of the slider.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-dragging
Present while the user is dragging.
data-orientation
Indicates the orientation of the slider.
data-disabled
Present when the slider is disabled.
data-valid
Present when the slider is in valid state (when wrapped in Field.Root).
data-invalid
Present when the slider is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the slider’s value has changed (when wrapped in Field.Root).
data-touched
Present when the slider has been touched (when wrapped in Field.Root).
data-focused
Present when the slider is focused (when wrapped in Field.Root).
| Attribute | Description | |
|---|---|---|
data-dragging | Present while the user is dragging. | |
data-orientation | Indicates the orientation of the slider. | |
data-disabled | Present when the slider is disabled. | |
data-valid | Present when the slider is in valid state (when wrapped in Field.Root). | |
data-invalid | Present when the slider is in invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the slider’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the slider has been touched (when wrapped in Field.Root). | |
data-focused | Present when the slider is focused (when wrapped in Field.Root). | |
Slider.Indicator.StateHide
Thumb
The draggable part of the slider at the tip of the indicator.
Renders a <div> element and a nested <input type="range">.
getAriaLabelfunction—
- Name
- Description
A function which returns a string value for the
aria-labelattribute of theinput.- Type
getAriaValueTextfunction—
- Name
- Description
A function which returns a string value for the
aria-valuetextattribute of theinput. This is important for screen reader users.- Type
indexnumber—
- Name
- Description
The index of the thumb which corresponds to the index of its value in the
valueordefaultValuearray. This prop is required to support server-side rendering for range sliders with multiple thumbs.- Type
- Example
onBlurfunction—
- Name
- Description
A blur handler forwarded to the
input.- Type
onFocusfunction—
- Name
- Description
A focus handler forwarded to the
input.- Type
tabIndexnumber—
- Name
- Description
Optional tab index attribute forwarded to the
input.- Type
disabledbooleanfalse
- Name
- Description
Whether the thumb should ignore user interaction.
- Type
- Default
false
inputRefReact.Ref<HTMLInputElement>—
- Name
- Description
A ref to access the nested input element.
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-dragging
Present while the user is dragging.
data-orientation
Indicates the orientation of the slider.
data-disabled
Present when the slider is disabled.
data-valid
Present when the slider is in valid state (when wrapped in Field.Root).
data-invalid
Present when the slider is in invalid state (when wrapped in Field.Root).
data-dirty
Present when the slider’s value has changed (when wrapped in Field.Root).
data-touched
Present when the slider has been touched (when wrapped in Field.Root).
data-focused
Present when the slider is focused (when wrapped in Field.Root).
data-index
Indicates the index of the thumb in range sliders.
| Attribute | Description | |
|---|---|---|
data-dragging | Present while the user is dragging. | |
data-orientation | Indicates the orientation of the slider. | |
data-disabled | Present when the slider is disabled. | |
data-valid | Present when the slider is in valid state (when wrapped in Field.Root). | |
data-invalid | Present when the slider is in invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the slider’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the slider has been touched (when wrapped in Field.Root). | |
data-focused | Present when the slider is focused (when wrapped in Field.Root). | |
data-index | Indicates the index of the thumb in range sliders. | |