Slider

A control element that allows for a range of selections.

Loading...

Anatomy

<Slider.Root>
  <Slider.Label />
  <Slider.ValueText />
  <Slider.Control>
    <Slider.Track>
      <Slider.Range />
    </Slider.Track>
    <Slider.Thumb>
      <Slider.HiddenInput />
    </Slider.Thumb>
  </Slider.Control>
  <Slider.MarkerGroup>
    <Slider.Marker />
  </Slider.MarkerGroup>
</Slider.Root>

Examples

Range

Render multiple Slider.Thumb parts for a range slider.

Marks

Add marks with Slider.MarkerGroup and Slider.Marker. Each marker's value sets its position on the track.

Min and Max

Set min and max to change the bounds. They default to 0 and 100. This example accepts -10 to 10.

Granularity

step sets the granularity. It defaults to 1, so values are integers. This example sets step to 0.01 for a value between 5 and 10 with two decimal places.

Change Events

onValueChange fires as the value changes. onValueChangeEnd fires when the interaction ends.

Orientation

Set orientation="vertical" for a vertical slider. The up and down arrow keys then change the value.

Give the vertical slider a height in your styles.

Origin

The origin defaults to the start of the track. Set origin to center to start from the middle.

Root Provider

Use RootProvider with the useSlider hook to access the state and methods from outside the component.

Dragging Indicator

Place Slider.DraggingIndicator inside Slider.Thumb to show an indicator while dragging.

With Tooltip

Render the thumb as a tooltip trigger to show the current value on hover, focus and drag.

With Number Input

Sync a range slider with number inputs so either one can set the value.

Thumb Overlap

Set minStepsBetweenThumbs to keep a minimum gap between range thumbs, as in a price filter.

Thumb Collision

thumbCollisionBehavior sets what happens when thumbs collide while dragging: push (default), swap or none.

API Reference

Props

Root

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
defaultValue
number[]

The initial value of the slider when rendered. Use when you don't need to control the value of the slider.

disabled
boolean

Whether the slider is disabled

form
string

The associate form of the underlying input element.

getAriaLabel
(details: ThumbLabelDetails) => string

Function that returns the accessible name of each thumb, e.g. "Minimum price"

getAriaLabelledBy
(details: ThumbLabelDetails) => string

Function that returns the `id` of the element that labels each thumb. Defaults to the label part when no `getAriaLabel` is provided.

getAriaValueText
(details: ValueTextDetails) => string

Function that returns a human readable value for the slider thumb

id
string

The unique identifier of the machine.

ids
ElementIds

The ids of the elements in the slider. Useful for composition.

invalid
boolean

Whether the slider is invalid

largeStep10 * step
number

The step value of the slider when the `Shift` key is held, or the `PageUp`/`PageDown` keys are used.

max100
number

The maximum value of the slider

min0
number

The minimum value of the slider

minStepsBetweenThumbs0
number

The minimum permitted steps between multiple thumbs. `minStepsBetweenThumbs` * `step` should reflect the gap between the thumbs. - `step: 1` and `minStepsBetweenThumbs: 10` => gap is `10` - `step: 10` and `minStepsBetweenThumbs: 2` => gap is `20`

name
string

The name associated with each slider thumb (when used in a form)

onFocusChange
(details: FocusChangeDetails) => void

Function invoked when the slider's focused index changes

onValueChange
(details: ValueChangeDetails) => void

Function invoked when the value of the slider changes

onValueChangeEnd
(details: ValueChangeDetails) => void

Function invoked when the slider value change is done

orientation'horizontal'
'horizontal' | 'vertical'

The orientation of the slider

origin'start'
SliderOrigin

The origin of the slider range. The track is filled from the origin to the thumb. - `"start"` / `"end"`: fill from `min` / `max` - `"center"`: fill from the midpoint of `min`/`max` - a `number`: fill from that value instead, for when the neutral point isn't the midpoint

readOnly
boolean

Whether the slider is read-only

render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<SliderRootState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

step1
number

The step value of the slider

thumbAlignment'contain'
'center' | 'contain'

The alignment of the slider thumb relative to the track - `center`: the thumb will extend beyond the bounds of the slider track. - `contain`: the thumb will be contained within the bounds of the track.

thumbCollisionBehavior'none'
'none' | 'push' | 'swap'

Controls how thumbs behave when they collide during pointer interactions. - `none` (default): Thumbs cannot move past each other; excess movement is ignored. - `push`: Thumbs push each other without restoring their previous positions when dragged back. - `swap`: Thumbs swap places when dragged past each other.

thumbSize
number | { width: number; height: number }

The slider thumbs dimensions. A number sets both the width and height.

value
number[]

The controlled value of the slider

AttributeDescription
[data-slider-root]<uid>
[data-disabled]Present when disabled
[data-orientation]The orientation of the slider
[data-dragging]Present when in the dragging state
[data-invalid]Present when invalid
[data-focus]Present when focused
CSS VariableDescription
--slider-thumb-widthThe thumb width of the slider
--slider-thumb-heightThe thumb height of the slider
--slider-thumb-transformThe thumb transform of the slider
--slider-range-startThe range start of the slider
--slider-range-endThe range end of the slider
--translate-xThe horizontal translation value
--translate-yThe vertical translation value

Control

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-slider-control]<uid>
[data-disabled]Present when disabled
[data-orientation]The orientation of the control
[data-dragging]Present when in the dragging state
[data-invalid]Present when invalid
[data-focus]Present when focused

DraggingIndicator

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-slider-dragging-indicator]<uid>
[data-orientation]The orientation of the draggingindicator
[data-state]"open" | "closed"

HiddenInput

Defines the <input> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Label

Defines the <label> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-slider-label]<uid>
[data-disabled]Present when disabled
[data-orientation]The orientation of the label
[data-dragging]Present when in the dragging state
[data-invalid]Present when invalid
[data-focus]Present when focused

MarkerGroup

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-slider-marker-group]<uid>
[data-orientation]The orientation of the markergroup

Marker

Defines the <span> element.

AttributeDefaultType
value
number

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<SliderMarkerState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-slider-marker]<uid>
[data-orientation]The orientation of the marker
[data-value]The value of the item
[data-disabled]Present when disabled
[data-state]"under-value" | "over-value" | "at-value"
[data-in-range]Present when is within the range

Range

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-slider-range]<uid>
[data-disabled]Present when disabled
[data-orientation]The orientation of the range
[data-dragging]Present when in the dragging state
[data-invalid]Present when invalid
[data-focus]Present when focused

RootProvider

Defines the <div> element.

AttributeDefaultType
value
UseSliderReturn

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<SliderRootProviderState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

Thumb

Defines the <div> element.

AttributeDefaultType
index
number

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
disabled
boolean

name
string

render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<SliderThumbState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-slider-thumb]<uid>
[data-index]The index of the item
[data-name]
[data-disabled]Present when disabled
[data-invalid]Present when invalid
[data-orientation]The orientation of the thumb
[data-focus]Present when focused
[data-dragging]Present when in the dragging state

Track

Defines the <div> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-slider-track]<uid>
[data-disabled]Present when disabled
[data-orientation]The orientation of the track
[data-dragging]Present when in the dragging state
[data-invalid]Present when invalid
[data-focus]Present when focused

ValueText

Defines the <span> element.

AttributeDefaultType
asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

For more details, read our Composition guide.
render
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>

Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state.

AttributeDescription
[data-slider-value-text]<uid>
[data-disabled]Present when disabled
[data-orientation]The orientation of the valuetext
[data-dragging]Present when in the dragging state
[data-invalid]Present when invalid
[data-focus]Present when focused

Context

API

PropertyType
value
number[]

The value of the slider.

dragging
boolean

Whether the slider is being dragged.

focused
boolean

Whether the slider is focused.

setValue
(value: number[]) => void

Function to set the value of the slider.

getThumbValue
(index: number) => number

Returns the value of the thumb at the given index.

setThumbValue
(index: number, value: number) => void

Sets the value of the thumb at the given index.

getValuePercent
(value: number) => number

Returns the percent of the thumb at the given index.

getPercentValue
(percent: number) => number

Returns the value of the thumb at the given percent.

getThumbPercent
(index: number) => number

Returns the percent of the thumb at the given index.

setThumbPercent
(index: number, percent: number) => void

Sets the percent of the thumb at the given index.

getThumbMin
(index: number) => number

Returns the min value of the thumb at the given index.

getThumbMax
(index: number) => number

Returns the max value of the thumb at the given index.

increment
(index: number) => void

Function to increment the value of the slider at the given index.

decrement
(index: number) => void

Function to decrement the value of the slider at the given index.

focus
VoidFunction

Function to focus the slider. This focuses the first thumb.

getRootState
() => RootState

Returns the state of the slider

getThumbState
(props: ThumbProps) => ThumbState

Returns the state of a specific thumb

getMarkerState
(props: MarkerProps) => MarkerState

Returns the state of a specific marker

Accessibility

Complies with the Slider WAI-ARIA design pattern.

Keyboard Support

KeyDescription
ArrowRight
Increments the slider based on defined step
ArrowLeft
Decrements the slider based on defined step
ArrowUp
Increases the value by the step amount.
ArrowDown
Decreases the value by the step amount.
PageUp
Increases the value by the largeStep amount.
PageDown
Decreases the value by the largeStep amount.
Shift + ArrowUp
Increases the value by the largeStep amount.
Shift + ArrowDown
Decreases the value by the largeStep amount.
Home
Sets the value to its minimum.
End
Sets the value to its maximum.