Skip to content

Slider API

API reference docs for the React Slider component. Learn about the props, CSS, and other APIs of this exported module.

Component demos

Import

import Slider from '@mui/material/Slider';
// or
import { Slider } from '@mui/material';
Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

aria-label

The label of the slider.

Type:string


aria-labelledby

The id of the element containing a label for the slider.

Type:string


aria-valuetext

A string value that provides a user-friendly name for the current value of the slider.

Type:string


classes

Override or extend the styles applied to the component.

See CSS API below for more details.

Type:object


color

The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization guide.

Type:'primary'
| 'secondary'
| 'error'
| 'info'
| 'success'
| 'warning'
| string

Default:'primary'


components

The components used for each slot inside.
This prop is an alias for the slots prop. It's recommended to use the slots prop instead.

Type:{ Input?: elementType, Mark?: elementType, MarkLabel?: elementType, Rail?: elementType, Root?: elementType, Thumb?: elementType, Track?: elementType, ValueLabel?: elementType }

Default:{}


componentsProps

The extra props for the slot components. You can override the existing props or add new ones.
This prop is an alias for the slotProps prop. It's recommended to use the slotProps prop instead, as componentsProps will be deprecated in the future.

Type:{ input?: func
| object, mark?: func
| object, markLabel?: func
| object, rail?: func
| object, root?: func
| object, thumb?: func
| object, track?: func
| object, valueLabel?: func
| { children?: element, className?: string, open?: bool, style?: object, value?: number, valueLabelDisplay?: 'auto'
| 'off'
| 'on' } }

Default:{}


defaultValue

The default value. Use when the component is not controlled.

Type:Array<number>
| number


disabled

If true, the component is disabled.

Type:bool

Default:false


disableSwap

If true, the active thumb doesn't swap when moving pointer over a thumb while dragging another thumb.

Type:bool

Default:false


getAriaLabel

Accepts a function which returns a string value that provides a user-friendly name for the thumb labels of the slider. This is important for screen reader users.

Type:func

Signature:
function(index: number) => string
  • index The thumb label's index to format.

getAriaValueText

Accepts a function which returns a string value that provides a user-friendly name for the current value of the slider. This is important for screen reader users.

Type:func

Signature:
function(value: number, index: number) => string
  • value The thumb label's value to format.
  • index The thumb label's index to format.

marks

Marks indicate predetermined values to which the user can move the slider. If true the marks are spaced according the value of the step prop. If an array, it should contain objects with value and an optional label keys.

Type:Array<{ label?: node, value: number }>
| bool

Default:false


max

The maximum allowed value of the slider. Should not be equal to min.

Type:number

Default:100


min

The minimum allowed value of the slider. Should not be equal to max.

Type:number

Default:0


name

Name attribute of the hidden input element.

Type:string


onChange

Callback function that is fired when the slider's value changed.

Type:func

Signature:
function(event: Event, value: number | Array, activeThumb: number) => void
  • event The event source of the callback. You can pull out the new value by accessing event.target.value (any). Warning: This is a generic event not a change event.
  • value The new value.
  • activeThumb Index of the currently moved thumb.

onChangeCommitted

Callback function that is fired when the mouseup is triggered.

Type:func

Signature:
function(event: React.SyntheticEvent | Event, value: number | Array) => void
  • event The event source of the callback. Warning: This is a generic event not a change event.
  • value The new value.

orientation

The component orientation.

Type:'horizontal'
| 'vertical'

Default:'horizontal'


scale

A transformation function, to change the scale of the slider.

Type:func

Default:function Identity(x) { return x; }

Signature:
function(x: any) => any

    size

    The size of the slider.

    Type:'small'
    | 'medium'
    | string

    Default:'medium'


    slotProps

    The props used for each slot inside the Slider.

    Type:{ input?: func
    | object, mark?: func
    | object, markLabel?: func
    | object, rail?: func
    | object, root?: func
    | object, thumb?: func
    | object, track?: func
    | object, valueLabel?: func
    | { children?: element, className?: string, open?: bool, style?: object, value?: number, valueLabelDisplay?: 'auto'
    | 'off'
    | 'on' } }

    Default:{}


    slots

    The components used for each slot inside the Slider. Either a string to use a HTML element or a component.

    Type:{ input?: elementType, mark?: elementType, markLabel?: elementType, rail?: elementType, root?: elementType, thumb?: elementType, track?: elementType, valueLabel?: elementType }

    Default:{}


    step

    The granularity with which the slider can step through values. (A "discrete" slider.) The min prop serves as the origin for the valid values. We recommend (max - min) to be evenly divisible by the step.
    When step is null, the thumb can only be slid onto marks provided with the marks prop.

    Type:number

    Default:1


    sx

    The system prop that allows defining system overrides as well as additional CSS styles.

    See the `sx` page for more details.

    Type:Array<func
    | object
    | bool>
    | func
    | object


    tabIndex

    Tab index attribute of the hidden input element.

    Type:number


    track

    The track presentation:

    • normal the track will render a bar representing the slider value.
    • inverted the track will render a bar representing the remaining slider value.
    • false the track will render without a bar.

    Type:'inverted'
    | 'normal'
    | false

    Default:'normal'


    value

    The value of the slider. For ranged sliders, provide an array with two values.

    Type:Array<number>
    | number


    valueLabelDisplay

    Controls when the value label is displayed:

    • auto the value label will display when the thumb is hovered or focused.
    • on will display persistently.
    • off will never display.

    Type:'auto'
    | 'off'
    | 'on'

    Default:'off'


    valueLabelFormat

    The format function the value label's value.
    When a function is provided, it should have the following signature:
    - {number} value The value label's value to format - {number} index The value label's index to format

    Type:func
    | string

    Default:function Identity(x) { return x; }


    The ref is forwarded to the root element.

    Theme default props

    You can use MuiSlider to change the default props of this component with the theme.


    CSS classes

    These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

    .Mui-activeSTATE

    State class applied to the thumb element if it's active.


    .Mui-disabledSTATE

    State class applied to the root and thumb element if disabled={true}.


    .Mui-focusVisibleSTATE

    State class applied to the thumb element if keyboard focused.


    .MuiSlider-colorError

    Styles applied to the root element if color="error".

    Rule name:colorError


    .MuiSlider-colorInfo

    Styles applied to the root element if color="info".

    Rule name:colorInfo


    .MuiSlider-colorPrimary

    Styles applied to the root element if color="primary".

    Rule name:colorPrimary


    .MuiSlider-colorSecondary

    Styles applied to the root element if color="secondary".

    Rule name:colorSecondary


    .MuiSlider-colorSuccess

    Styles applied to the root element if color="success".

    Rule name:colorSuccess


    .MuiSlider-colorWarning

    Styles applied to the root element if color="warning".

    Rule name:colorWarning


    .MuiSlider-dragging

    State class applied to the root if a thumb is being dragged.

    Rule name:dragging


    .MuiSlider-mark

    Styles applied to the mark element.

    Rule name:mark


    .MuiSlider-markActive

    Styles applied to the mark element if active (depending on the value).

    Rule name:markActive


    .MuiSlider-marked

    Styles applied to the root element if marks is provided with at least one label.

    Rule name:marked


    .MuiSlider-markLabel

    Styles applied to the mark label element.

    Rule name:markLabel


    .MuiSlider-markLabelActive

    Styles applied to the mark label element if active (depending on the value).

    Rule name:markLabelActive


    .MuiSlider-rail

    Styles applied to the rail element.

    Rule name:rail


    .MuiSlider-root

    Styles applied to the root element.

    Rule name:root


    .MuiSlider-sizeSmall

    Styles applied to the root element if size="small".

    Rule name:sizeSmall


    .MuiSlider-thumb

    Styles applied to the thumb element.

    Rule name:thumb


    .MuiSlider-thumbColorError

    Styles applied to the thumb element if color="error".

    Rule name:thumbColorError


    .MuiSlider-thumbColorInfo

    Styles applied to the thumb element if color="info".

    Rule name:thumbColorInfo


    .MuiSlider-thumbColorPrimary

    Styles applied to the thumb element if color="primary".

    Rule name:thumbColorPrimary


    .MuiSlider-thumbColorSecondary

    Styles applied to the thumb element if color="secondary".

    Rule name:thumbColorSecondary


    .MuiSlider-thumbColorSuccess

    Styles applied to the thumb element if color="success".

    Rule name:thumbColorSuccess


    .MuiSlider-thumbColorWarning

    Styles applied to the thumb element if color="warning".

    Rule name:thumbColorWarning


    .MuiSlider-thumbSizeSmall

    Styles applied to the thumb element if size="small".

    Rule name:thumbSizeSmall


    .MuiSlider-track

    Styles applied to the track element.

    Rule name:track


    .MuiSlider-trackFalse

    Styles applied to the root element if track={false}.

    Rule name:trackFalse


    .MuiSlider-trackInverted

    Styles applied to the root element if track="inverted".

    Rule name:trackInverted


    .MuiSlider-valueLabel

    Styles applied to the thumb label element.

    Rule name:valueLabel


    .MuiSlider-valueLabelCircle

    Styles applied to the thumb label's circle element.

    Rule name:valueLabelCircle


    .MuiSlider-valueLabelLabel

    Styles applied to the thumb label's label element.

    Rule name:valueLabelLabel


    .MuiSlider-valueLabelOpen

    Styles applied to the thumb label element if it's open.

    Rule name:valueLabelOpen


    .MuiSlider-vertical

    Styles applied to the root element if orientation="vertical".

    Rule name:vertical



    You can override the style of the component using one of these customization options: