Slider
An easily stylable range input.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { Slider } from '@base-ui-components/react/slider';
<Slider.Root>
  <Slider.Value />
  <Slider.Control>
    <Slider.Track>
      <Slider.Indicator />
      <Slider.Thumb />
    </Slider.Track>
  </Slider.Control>
</Slider.Root>API reference
Root
Groups all parts of the slider.
Renders a <div> element.
namestring
—
namestring
—- Name
- Description
- Identifies the field when a form is submitted. 
- Type
- string | undefined
defaultValuenumber | number[]
—
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
- number | number[] | undefined
valuenumber | number[]
—
valuenumber | number[]
—- Name
- Description
- The value of the slider. For ranged sliders, provide an array with two values. 
- Type
- number | number[] | undefined
onValueChangefunction
—
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).
- Type
- | (( value: number | number[], eventDetails: { reason: 'none' event: ReasonToEvent cancel: () => void allowPropagation: () => void isCanceled: boolean isPropagationAllowed: boolean trigger: HTMLElement | undefined } & { activeThumbIndex: number }, ) => void) | undefined
onValueCommittedfunction
—
onValueCommittedfunction
—- Name
- Description
- Callback function that is fired when the - pointerupis triggered. Warning: This is a generic event not a change event.
- Type
- | (( value: number | number[], eventDetails: Slider.Root.CommitEventDetails, ) => void) | undefined
localeIntl.LocalesArgument
—
localeIntl.LocalesArgument
—- Name
- Description
- The locale used by - Intl.NumberFormatwhen formatting the value. Defaults to the user's runtime locale.
- Type
- Intl.LocalesArgument | undefined
refRefObject<HTMLDivElement>
—
refRefObject<HTMLDivElement>
—- Name
- Type
- React.RefObject<HTMLDivElement> | undefined
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
- | React.CSSProperties | ((state: Slider.Root.State) => CSSProperties | undefined) | undefined
thumbAlignmentUnion
'center'
thumbAlignmentUnion
'center'
- Name
- Description
- How the thumb(s) are aligned relative to - Slider.Controlwhen the value is at- minor- max:- center: The center of the thumb is aligned with the control edge
- edge: The thumb is inset within the control such that its edge is aligned with the control edge
- edge-client-only: Same as- edgebut renders after React hydration on the client, reducing bundle size in return
 
- Type
- 'center' | 'edge' | 'edge-client-only' | undefined
- Default
- 'center'
stepnumber
1
stepnumber
1
- 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
- number | undefined
- Default
- 1
largeStepnumber
10
largeStepnumber
10
- 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
- number | undefined
- Default
- 10
minStepsBetweenValuesnumber
0
minStepsBetweenValuesnumber
0
- Description
- The minimum steps between values in a range slider. 
- Type
- number | undefined
- Default
- 0
minnumber
0
minnumber
0
- Name
- Description
- The minimum allowed value of the slider. Should not be equal to max. 
- Type
- number | undefined
- Default
- 0
maxnumber
100
maxnumber
100
- Name
- Description
- The maximum allowed value of the slider. Should not be equal to min. 
- Type
- number | undefined
- Default
- 100
formatIntl.NumberFormatOptions
—
formatIntl.NumberFormatOptions
—- Name
- Description
- Options to format the input value. 
- Type
- Intl.NumberFormatOptions | undefined
disabledboolean
false
disabledboolean
false
- Name
- Description
- Whether the slider should ignore user interaction. 
- Type
- boolean | undefined
- Default
- false
orientationOrientation
'horizontal'
orientationOrientation
'horizontal'
- Name
- Description
- The component orientation. 
- Type
- 'horizontal' | 'vertical' | undefined
- Default
- 'horizontal'
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Slider.Root.State) => string | undefined)
renderReactElement | function
—
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
- | ReactElement | (( props: HTMLProps, state: Slider.Root.State, ) => ReactElement)
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-readonly
Present when the slider is readonly.
data-required
Present when the slider is required.
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).
Value
Displays the current value of the slider as text.
Renders an <output> element.
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
- | React.CSSProperties | ((state: Slider.Root.State) => CSSProperties | undefined) | undefined
children((formattedValues: string[], values: number[]) => ReactNode) | null
—
children((formattedValues: string[], values: number[]) => ReactNode) | null
—- Name
- Type
- | (( formattedValues: string[], values: number[], ) => ReactNode) | null | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Slider.Root.State) => string | undefined)
renderReactElement | function
—
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
- | ReactElement | (( props: HTMLProps, state: Slider.Root.State, ) => ReactElement)
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-readonly
Present when the slider is readonly.
data-required
Present when the slider is required.
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).
Control
The clickable, interactive part of the slider.
Renders a <div> element.
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
- | React.CSSProperties | ((state: Slider.Root.State) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Slider.Root.State) => string | undefined)
renderReactElement | function
—
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
- | ReactElement | (( props: HTMLProps, state: Slider.Root.State, ) => ReactElement)
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-readonly
Present when the slider is readonly.
data-required
Present when the slider is required.
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).
Track
Contains the slider indicator and represents the entire range of the slider.
Renders a <div> element.
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
- | React.CSSProperties | ((state: Slider.Root.State) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Slider.Root.State) => string | undefined)
renderReactElement | function
—
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
- | ReactElement | (( props: HTMLProps, state: Slider.Root.State, ) => ReactElement)
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-readonly
Present when the slider is readonly.
data-required
Present when the slider is required.
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).
Indicator
Visualizes the current value of the slider.
Renders a <div> element.
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
- | React.CSSProperties | ((state: Slider.Root.State) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Slider.Root.State) => string | undefined)
renderReactElement | function
—
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
- | ReactElement | (( props: HTMLProps, state: Slider.Root.State, ) => ReactElement)
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-readonly
Present when the slider is readonly.
data-required
Present when the slider is required.
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).
Thumb
The draggable part of the the slider at the tip of the indicator.
Renders a <div> element and a nested <input type="range">.
getAriaLabelfunction
—
getAriaLabelfunction
—- Name
- Description
- A function which returns a string value for the - aria-labelattribute of the- input.
- Type
- ((index: number) => string) | null | undefined
getAriaValueTextfunction
—
getAriaValueTextfunction
—- Name
- Description
- A function which returns a string value for the - aria-valuetextattribute of the- input. This is important for screen reader users.
- Type
- | (( formattedValue: string, value: number, index: number, ) => string) | null | undefined
indexnumber
—
indexnumber
—- Name
- Description
- The index of the thumb which corresponds to the index of its value in the - valueor- defaultValuearray. This prop is required to support server-side rendering for range sliders with multiple thumbs.
- Type
- number | undefined
- Example
- <Slider.Root value={[10, 20]}> <Slider.Thumb index={0} /> <Slider.Thumb index={1} /> </Slider.Root>
onBlurfunction
—
onBlurfunction
—- Name
- Description
- A blur handler forwarded to the - input.
- Type
- | React.FocusEventHandler<HTMLInputElement> | undefined
onFocusfunction
—
onFocusfunction
—- Name
- Description
- A focus handler forwarded to the - input.
- Type
- | React.FocusEventHandler<HTMLInputElement> | undefined
styleReact.CSSProperties | function
—
styleReact.CSSProperties | function
—- Name
- Type
- | React.CSSProperties | ((state: Slider.Thumb.State) => CSSProperties | undefined) | undefined
tabIndexnumber
—
tabIndexnumber
—- Name
- Description
- Optional tab index attribute forwarded to the - input.
- Type
- number | undefined
disabledboolean
false
disabledboolean
false
- Name
- Description
- Whether the thumb should ignore user interaction. 
- Type
- boolean | undefined
- Default
- false
inputRefRef<HTMLInputElement>
—
inputRefRef<HTMLInputElement>
—- Name
- Description
- A ref to access the nested input element. 
- Type
- React.Ref<HTMLInputElement> | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Slider.Thumb.State) => string | undefined)
renderReactElement | function
—
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
- | ReactElement | (( props: HTMLProps, state: Slider.Thumb.State, ) => ReactElement)
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-readonly
Present when the slider is readonly.
data-required
Present when the slider is required.
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.
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
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.