Slider API
Demos
For examples and details on the usage of this React component, visit the component demo pages:
Import
import Slider from '@mui/joy/Slider';
// or
import { Slider } from '@mui/joy';Props
A string value that provides a user-friendly name for the current value of the slider.
Type:
stringOverride or extend the styles applied to the component.
See CSS API below for more details.
Type:
objectThe 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.
Type:
'danger' | 'neutral' | 'primary' | 'success' | 'warning' | stringDefault:
'primary'The component used for the root node. Either a string to use a HTML element or a component.
Type:
elementTypeIf true, the active thumb doesn't swap when moving pointer over a thumb while dragging another thumb.
Type:
boolDefault:
falseAccepts 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:
funcSignature:
function(index: number) => string- indexThe 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:
funcSignature:
function(value: number, index: number) => string- valueThe thumb label's value to format.
- indexThe thumb label's index to format.
If true the Slider will be rendered right-to-left (with the lowest value on the right-hand side).
Type:
boolDefault:
falseMarks 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 }> | boolDefault:
falseCallback function that is fired when the slider's value changed.
Type:
funcSignature:
function(event: Event, value: number | Array, activeThumb: number) => void - eventThe 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.
- valueThe new value.
- activeThumbIndex of the currently moved thumb.
Callback function that is fired when the mouseup is triggered.
Type:
funcSignature:
function(event: React.SyntheticEvent | Event, value: number | Array) => void - eventThe event source of the callback. Warning: This is a generic event not a change event.
- valueThe new value.
A transformation function, to change the scale of the slider.
Type:
funcDefault:
function Identity(x) {
  return x;
}Signature:
function(x: any) => anyThe 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.
Type:
'sm' | 'md' | 'lg' | stringDefault:
'md'The props used for each slot inside.
Type:
{ input?: func | object, mark?: func | object, markLabel?: func | object, rail?: func | object, root?: func | object, thumb?: func | object, track?: func | object, valueLabel?: func | object }Default:
{}The components used for each slot inside.
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:
{}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:
numberDefault:
1The 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 | objectThe 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' | falseDefault:
'normal'The value of the slider. For ranged sliders, provide an array with two values.
Type:
Array<number> | numberControls 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'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 | stringDefault:
function Identity(x) {
  return x;
}The global variant to use.
To learn how to add your own variants, check out Themed components—Extend variants.
Type:
'outlined' | 'plain' | 'soft' | 'solid' | stringDefault:
'solid'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.
The component that renders the mark label.
Default: 'span'
Global class: .MuiSlider-markLabel
The component that renders the value label.
Default: 'span'
Global class: .MuiSlider-valueLabel
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.
CSS classes
These class names are useful for styling with CSS. They are applied to the root slot when specific states are triggered.
Class name applied to the root element if marks is provided with at least one label.