Slider API
API reference docs for the React Slider component. Learn about the props, CSS, and other APIs of this exported module.
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 of the native component are also available.
| Name | Type | Default | Description |
|---|---|---|---|
| aria-label | string | - | The label of the slider. |
| aria-labelledby | string | - | The id of the element containing a label for the slider. |
| aria-valuetext | string | - | A string value that provides a user-friendly name for the current value of the slider. |
| classes | object | - | Override or extend the styles applied to the component. See CSS classes API below for more details. |
| color | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | string | 'primary' | The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization guide. |
| defaultValue | Array<number> | number | - | The default value. Use when the component is not controlled. |
| disabled | bool | false | If |
| disableSwap | bool | false | If |
| getAriaLabel | func | - | 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
|
| getAriaValueText | func | - | 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
|
| marks | Array<{ label?: node, value: number }> | bool | false | Marks indicate predetermined values to which the user can move the slider. If |
| max | number | 100 | The maximum allowed value of the slider. Should not be equal to min. |
| min | number | 0 | The minimum allowed value of the slider. Should not be equal to max. |
| name | string | - | Name attribute of the hidden |
| onChange | func | - | Callback function that is fired when the slider's value changed. Signature: function(event: Event, value: Value, activeThumb: number) => void
|
| onChangeCommitted | func | - | Callback function that is fired when the Signature: function(event: React.SyntheticEvent | Event, value: Value) => void
|
| orientation | 'horizontal' | 'vertical' | 'horizontal' | The component orientation. |
| scale | func | function Identity(x) { return x; } | A transformation function, to change the scale of the slider. Signature: function(x: any) => any |
| shiftStep | number | 10 | The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down. |
| size | 'small' | 'medium' | string | 'medium' | The size of the slider. |
| slotProps | { 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?: node, valueLabelDisplay?: 'auto' | 'off' | 'on' } } | {} | 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. |
| step | number | 1 | The granularity with which the slider can step through values. (A "discrete" slider.) The |
| sx | Array<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. |
| tabIndex | number | - | Tab index attribute of the hidden |
| track | 'inverted' | 'normal' | false | 'normal' | The track presentation:
|
| value | Array<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:
|
| valueLabelFormat | func | string | function Identity(x) { return x; } | The format function the value label's value. |
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.
| Slot name | Class name | Default component | Description |
|---|---|---|---|
| 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 | .MuiSlider-valueLabel | SliderValueLabel | The component that renders the value label. |
| input | 'input' | The component that renders the input. |
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
| Class name | Rule name | Description |
|---|---|---|
| .Mui-active | State class applied to the thumb element if it's active. | |
| .Mui-disabled | State class applied to the root and thumb element if disabled={true}. | |
| .Mui-focusVisible | State class applied to the thumb element if keyboard focused. | |
| .MuiSlider-colorError | colorError | Styles applied to the root element if color="error". |
| .MuiSlider-colorInfo | colorInfo | Styles applied to the root element if color="info". |
| .MuiSlider-colorPrimary | colorPrimary | Styles applied to the root element if color="primary". |
| .MuiSlider-colorSecondary | colorSecondary | Styles applied to the root element if color="secondary". |
| .MuiSlider-colorSuccess | colorSuccess | Styles applied to the root element if color="success". |
| .MuiSlider-colorWarning | colorWarning | Styles applied to the root element if color="warning". |
| .MuiSlider-dragging | dragging | State class applied to the root if a thumb is being dragged. |
| .MuiSlider-markActive | markActive | Styles applied to the mark element if active (depending on the value). |
| .MuiSlider-marked | marked | Styles applied to the root element if marks is provided with at least one label. |
| .MuiSlider-markLabelActive | markLabelActive | Styles applied to the mark label element if active (depending on the value). |
| .MuiSlider-sizeSmall | sizeSmall | Styles applied to the root element if size="small". |
| .MuiSlider-thumbColorError | thumbColorError | Styles applied to the thumb element if color="error". |
| .MuiSlider-thumbColorInfo | thumbColorInfo | Styles applied to the thumb element if color="info". |
| .MuiSlider-thumbColorPrimary | thumbColorPrimary | Styles applied to the thumb element if color="primary". |
| .MuiSlider-thumbColorSecondary | thumbColorSecondary | Styles applied to the thumb element if color="secondary". |
| .MuiSlider-thumbColorSuccess | thumbColorSuccess | Styles applied to the thumb element if color="success". |
| .MuiSlider-thumbColorWarning | thumbColorWarning | Styles applied to the thumb element if color="warning". |
| .MuiSlider-thumbSizeSmall | thumbSizeSmall | Styles applied to the thumb element if size="small". |
| .MuiSlider-trackFalse | trackFalse | Styles applied to the root element if track={false}. |
| .MuiSlider-trackInverted | trackInverted | Styles applied to the root element if track="inverted". |
| .MuiSlider-valueLabelCircle | valueLabelCircle | Styles applied to the thumb label's circle element. |
| .MuiSlider-valueLabelLabel | valueLabelLabel | Styles applied to the thumb label's label element. |
| .MuiSlider-valueLabelOpen | valueLabelOpen | Styles applied to the thumb label element if it's open. |
| .MuiSlider-vertical | vertical | Styles applied to the root element if orientation="vertical". |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverridesproperty in a custom theme.
Source code
If you did not find the information in this page, consider having a look at the implementation of the component for more detail.