Skip to content
+

Slider

A slider is a UI element that lets users select a single value or a range of values along a bar.

Slider API

Import

import { Slider } from '@mui/base/Slider';
// or
import { Slider } from '@mui/base';
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


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.

isRtl

If true the Slider will be rendered right-to-left (with the lowest value on the right-hand side).

Type:bool

Default:false


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

    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?: any
    | func }

    Default:{}


    slots

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

    See Slots API below for more details.

    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


    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


    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.

    Slots

    To learn how to customize the slot, check out the Overriding component structure guide.

    root

    The component that renders the root.

    Class name: .base-Slider-root

    Default component: 'span'


    track

    The component that renders the track.

    Class name: .base-Slider-track

    Default component: 'span'


    rail

    The component that renders the rail.

    Class name: .base-Slider-rail

    Default component: 'span'


    thumb

    The component that renders the thumb.

    Class name: .base-Slider-thumb

    Default component: 'span'


    mark

    The component that renders the mark.

    Class name: .base-Slider-mark

    Default component: 'span'


    markLabel

    The component that renders the mark label.

    Class name: .base-Slider-markLabel

    Default component: 'span'


    valueLabel

    The component that renders the value label.


    input

    The component that renders the input.

    Default component: 'input'


    CSS classes

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

    .base--activeSTATE

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


    .base--disabledSTATE

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


    .base--focusVisibleSTATE

    State class applied to the thumb element if keyboard focused.


    .base-Slider-dragging

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


    .base-Slider-markActive

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


    .base-Slider-marked

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


    .base-Slider-markLabelActive

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


    .base-Slider-trackFalse

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


    .base-Slider-trackInverted

    Class name applied to the root element if track="inverted".


    .base-Slider-vertical

    Class name applied to the root element if orientation="vertical".