Slider API
Demos
For examples and details on the usage of this React component, visit the component demo pages:
Import
import Slider from '@mui/material/Slider';
// or
import { Slider } from '@mui/material';
Props
Props of the native component are also available.
A string value that provides a user-friendly name for the current value of the slider.
Type:
string
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' | string
Default:
'primary'
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:
{}
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:
{}
If true
, the active thumb doesn't swap when moving pointer over a thumb while dragging another thumb.
Type:
bool
Default:
false
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.
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 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
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 accessingevent.target.value
(any). Warning: This is a generic event not a change event.value
The new value.activeThumb
Index of the currently moved thumb.
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.
A transformation function, to change the scale of the slider.
Type:
func
Default:
function Identity(x) {
return x;
}
Signature:
function(x: any) => any
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:
{}
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:
{}
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
The system prop that allows defining system overrides as well as additional CSS styles.
Type:
Array<func | object | bool> | func | object
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'
The value of the slider. For ranged sliders, provide an array with two values.
Type:
Array<number> | number
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'
ref
is forwarded to the root element.Theme default props
You can useMuiSlider
to change the default props of this component with the theme.CSS
The following class names are useful for styling with CSS (the state classes are marked).
To learn more, visit the component customization page.
Styles applied to the root element if marks
is provided with at least one label.
Styles applied to the mark element if active (depending on the value).
Styles applied to the mark label element if active (depending on the value).
Styles applied to the thumb element if color="primary"
.
Styles applied to the thumb element if color="secondary"
.
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
styleOverrides
property in a custom theme.