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/joy/Slider';
// or
import { Slider } from '@mui/joy';
Learn about the difference by reading this guide on minimizing bundle size.

Props

NameTypeDefaultDescription
aria-labelstring

The label of the slider.

aria-valuetextstring

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

classesobject

Override or extend the styles applied to the component.

See CSS API below for more details.

color'danger'
| 'neutral'
| 'primary'
| 'success'
| 'warning'
| string
'primary'

The color of the component. It supports those theme colors that make sense for this component.

To learn how to add your own colors, check out Themed components—Extend colors.

componentelementType

The component used for the root node. Either a string to use a HTML element or a component.

defaultValueArray<number>
| number

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

disabledboolfalse

If true, the component is disabled.

disableSwapboolfalse

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

getAriaLabelfunc

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.

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

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.

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

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

marksArray<{ label?: node, value: number }>
| bool
false

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.

maxnumber100

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

minnumber0

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

namestring

Name attribute of the hidden input element.

onChangefunc

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

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.
onChangeCommittedfunc

Callback function that is fired when the mouseup is triggered.

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'horizontal'
| 'vertical'
'horizontal'

The component orientation.

scalefuncfunction Identity(x) { return x; }

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

Signature:function(x: any) => any
    shiftStepnumber10

    The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.

    size'sm'
    | 'md'
    | 'lg'
    | string
    'md'

    The size of the component. It accepts theme values between 'sm' and 'lg'.

    To learn how to add custom sizes to the component, check out Themed components—Extend sizes.

    slotProps{ input?: func
    | object, mark?: func
    | object, markLabel?: func
    | object, rail?: func
    | object, root?: func
    | object, thumb?: func
    | object, track?: func
    | object, valueLabel?: func
    | object }
    {}

    The props used for each slot inside.

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

    The components used for each slot inside.

    See Slots API below for more details.

    stepnumber1

    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.

    sxArray<func
    | object
    | bool>
    | func
    | object

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

    See the `sx` page for more details.

    tabIndexnumber

    Tab index attribute of the hidden input element.

    track'inverted'
    | 'normal'
    | false
    'normal'

    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.
    valueArray<number>
    | number

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

    valueLabelDisplay'auto'
    | 'off'
    | 'on'
    'off'

    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.
    valueLabelFormatfunc
    | string
    function Identity(x) { return x; }

    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

    variant'outlined'
    | 'plain'
    | 'soft'
    | 'solid'
    | string
    'solid'

    The global variant to use.

    To learn how to add your own variants, check out Themed components—Extend variants.

    The ref is forwarded to the root element.

    Theme default props

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


    Slots

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

    Slot nameClass nameDefault componentDescription
    root.MuiSlider-root'span'The component that renders the root.
    track.MuiSlider-track'span'The component that renders the track.
    rail.MuiSlider-rail'span'The component that renders the rail.
    thumb.MuiSlider-thumb'span'The component that renders the thumb.
    mark.MuiSlider-mark'span'The component that renders the mark.
    markLabel.MuiSlider-markLabel'span'The component that renders the mark label.
    valueLabel'span'The component that renders the value label.
    input'input'The component that renders the 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.

    Class nameRule nameDescription
    .Mui-activeState class applied to the thumb element if it's active.
    .Mui-disabledState class applied to the root and thumb element if disabled={true}.
    .Mui-focusVisibleState class applied to the thumb element if keyboard focused.
    .MuiSlider-draggingdraggingState class applied to the root if a thumb is being dragged.
    .MuiSlider-markActivemarkActiveClass name applied to the mark element if active (depending on the value).
    .MuiSlider-markedmarkedClass name applied to the root element if marks is provided with at least one label.
    .MuiSlider-markLabelActivemarkLabelActiveClass name applied to the mark label element if active (depending on the value).
    .MuiSlider-trackFalsetrackFalseClass name applied to the root element if track={false}.
    .MuiSlider-trackInvertedtrackInvertedClass name applied to the root element if track="inverted".
    .MuiSlider-verticalverticalClass name applied to the root element if orientation="vertical".

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