Skip to main content
Sliders allow users to make selections from a range of values.

Import

import Slider from '@mui/material/Slider';

Basic Usage

import * as React from 'react';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import Slider from '@mui/material/Slider';
import VolumeDown from '@mui/icons-material/VolumeDown';
import VolumeUp from '@mui/icons-material/VolumeUp';

export default function ContinuousSlider() {
  const [value, setValue] = React.useState<number>(30);

  const handleChange = (event: Event, newValue: number) => {
    setValue(newValue);
  };

  return (
    <Box sx={{ width: 200 }}>
      <Stack spacing={2} direction="row" sx={{ alignItems: 'center', mb: 1 }}>
        <VolumeDown />
        <Slider aria-label="Volume" value={value} onChange={handleChange} />
        <VolumeUp />
      </Stack>
      <Slider disabled defaultValue={30} aria-label="Disabled slider" />
    </Box>
  );
}

Props

value
number | number[]
The value of the slider. For ranged sliders, provide an array with two values.
defaultValue
number | number[]
The default value. Use when the component is not controlled.
min
number
default:"0"
The minimum allowed value of the slider. Should not be equal to max.
max
number
default:"100"
The maximum allowed value of the slider. Should not be equal to min.
step
number | null
default:"1"
The granularity with which the slider can step through values. When step is null, the thumb can only be slid onto marks provided with the marks prop.
marks
boolean | Mark[]
default:"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.
color
'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning'
default:"'primary'"
The color of the component. Supports both default and custom theme colors.
size
'small' | 'medium'
default:"'medium'"
The size of the slider.
orientation
'horizontal' | 'vertical'
default:"'horizontal'"
The component orientation.
disabled
boolean
default:"false"
If true, the component is disabled.
disableSwap
boolean
default:"false"
If true, the active thumb doesn’t swap when moving pointer over a thumb while dragging another thumb.
track
'normal' | false | 'inverted'
default:"'normal'"
The track presentation. normal renders a bar representing the slider value. inverted renders a bar representing the remaining slider value. false renders without a bar.
valueLabelDisplay
'on' | 'auto' | 'off'
default:"'off'"
Controls when the value label is displayed. auto displays when the thumb is hovered or focused. on displays persistently. off never displays.
valueLabelFormat
string | ((value: number, index: number) => ReactNode)
The format function the value label’s value. Default is identity function.
onChange
(event: Event, value: number | number[], activeThumb: number) => void
Callback function that is fired when the slider’s value changed. You can pull out the new value by accessing event.target.value (any).
onChangeCommitted
(event: React.SyntheticEvent | Event, value: number | number[]) => void
Callback function that is fired when the mouseup is triggered.
getAriaLabel
(index: number) => string
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.
getAriaValueText
(value: number, index: number) => string
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.
scale
(value: number) => number
A transformation function, to change the scale of the slider. Default is identity function.
sx
SxProps<Theme>
The system prop that allows defining system overrides as well as additional CSS styles.

API Reference

Build docs developers (and LLMs) love