Slider
A slider lets the user choose a number by dragging a thumb along a track. Use a range slider when the user chooses an interval between two values.
A slider has no intrinsic width. Give it a width, or place it in a container that has one.
Usage
<Slider
defaultValue={40}
marks={[
{ value: 20, label: '20%' },
{ value: 50, label: '50%' },
{ value: 80, label: '80%' },
]}
label={(value) => `${value}%`}
aria-label="Fyllingsgrad"
/>
Label
The label shows the value above the thumb while the user drags. Pass a function to format it, or null to hide it.
<Slider defaultValue={250} min={0} max={1000} step={50} label={(value) => `${value} kr`} />
<Slider defaultValue={40} label={null} />
<Slider defaultValue={70} labelAlwaysOn />
Min, max and step
<Slider defaultValue={20} min={0} max={100} step={10} />
<Slider defaultValue={0.5} min={0} max={1} step={0.1} />
Marks
Marks label fixed values on the track. Add restrictToMarks to allow only those values.
<Slider
defaultValue={50}
marks={[
{ value: 0, label: 'Lav' },
{ value: 50, label: 'Middels' },
{ value: 100, label: 'Høy' },
]}
/>
<Slider defaultValue={50} restrictToMarks marks={[...]} />
onChangeEnd
onChange fires on every step while dragging. onChangeEnd fires once, when the user releases the thumb or finishes a keyboard change — use it to save or fetch.
Valgt: 40 — lagret: 40
const [value, setValue] = useState(40);
const [committed, setCommitted] = useState(40);
<Slider value={value} onChange={setValue} onChangeEnd={setCommitted} />
Range slider
RangeSlider takes and returns a pair of values, [from, to]. It shares the label, step and marks options with Slider. Its own options are below.
<RangeSlider
defaultValue={[20, 60]}
marks={[
{ value: 20, label: '20%' },
{ value: 50, label: '50%' },
{ value: 80, label: '80%' },
]}
label={(value) => `${value}%`}
thumbFromLabel="Fra"
thumbToLabel="Til"
/>
Minimum and maximum range
minRange sets the smallest distance between the thumbs, and maxRange the largest. minRange defaults to 10. By default a thumb pushes the other one when the limit is reached; set pushOnOverlap={false} to stop it instead.
<RangeSlider defaultValue={[20, 60]} minRange={20} />
<RangeSlider defaultValue={[20, 60]} maxRange={50} />
<RangeSlider defaultValue={[20, 60]} minRange={20} pushOnOverlap={false} />
Marks and formatted values
<RangeSlider
defaultValue={[2000, 6000]}
min={0}
max={10000}
step={500}
minRange={500}
label={(value) => `${value} kr`}
marks={[
{ value: 0, label: '0' },
{ value: 5000, label: '5 000' },
{ value: 10000, label: '10 000' },
]}
/>
Props
Only what this design system changes. Everything else is Mantine's — read the props for Slider and RangeSlider there.
| Property | Type | Allowed values | Default | Description |
|---|---|---|---|---|
| — | — | — | — | The value label gets padding-inline: var(--mantine-spacing-xs) on both components. |
Accessibility
Give each slider an aria-label naming the value it controls — Mantine does not infer one from surrounding text. On a range slider, label the thumbs with thumbFromLabel and thumbToLabel. When the label formats the value, for example as currency, set thumbValueText so a screen reader reads the same text. See
Accessibility for the rest.