Slider
An easily stylable range input.
Usage guidelines
- Form controls must have an accessible name: Prefer
<Slider.Label>, or provide anaria-labelon each<Slider.Thumb>when no visible label is rendered. See Labeling a slider and the forms guide.
Anatomy
Import the component and assemble its parts:
Examples
Labeling a slider
A single-thumb slider without a visible label (such as a volume control) can be labeled using aria-label on <Slider.Thumb>:
A visible label can be created using <Slider.Label>:
For a multi-thumb range slider with a visible label, add aria-label on each <Slider.Thumb> to distinguish them:
Range slider
To create a range slider:
- Pass an array of values and place a
<Slider.Thumb>for each value in the array - Additionally for server-side rendering, specify a numeric
indexfor each thumb that corresponds to the index of its value in the value array
Thumbs can be configured to behave differently when they collide during pointer interactions using the thumbCollisionBehavior prop on <Slider.Root>.
Steps
Use the step prop to snap the value to multiples of a given increment, and largeStep to control the increment when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.
Marks
Render your own tick marks, positioning each mark along the track as a percentage of the value range.
Marks are independent of the value's granularity—pair them with the step prop to snap the thumb to each mark.
Thumb alignment
Set thumbAlignment="edge" to inset the thumb such that its edge aligns with the edge of the control when the value is at min or max, without overflowing the control like the default "center" alignment.
A client-only alternative thumbAlignment="edge-client-only" can be used to reduce bundle size but only renders after Svelte hydration.
Vertical
Set orientation="vertical" on <Slider.Root> to build a vertical slider.
Form integration
To use a slider in a form, pass the slider name to <Slider.Root>:
For grouped multi-thumb range sliders in forms, Fieldset can provide the shared visible label while each thumb keeps its own aria-label:
API reference
Root
Groups all parts of the slider. Renders a <div> element.
defaultValue SliderValue —
- Name
- Description
The value an empty
valuestarts from.- Type
SliderValue
disabled boolean | null false
- Name
- Description
Whether the slider should ignore user interaction.
- Type
boolean | null- Default
false
format Intl.NumberFormatOptions —
- Name
- Description
Options to format the value.
- Type
Intl.NumberFormatOptions
locale Intl.LocalesArgument —
- Name
- Description
The locale used by
Intl.NumberFormatwhen formatting the value. Defaults to the user's runtime locale.- Type
Intl.LocalesArgument
max number 100
- Name
- Description
The maximum allowed value of the slider. Should not be equal to min.
- Type
number- Default
100
min number 0
- Name
- Description
The minimum allowed value of the slider. Should not be equal to max.
- Type
number- Default
0
minStepsBetweenValues number 0
- Description
The minimum steps between values in a range slider.
- Type
number- Default
0
name string | null —
- Name
- Description
Identifies the field when a form is submitted.
- Type
string | null
form string | null —
- Name
- Description
Identifies the form that owns the slider inputs.
- Type
string | null
orientation SliderOrientation 'horizontal'
- Name
- Description
The component orientation.
- Type
SliderOrientation- Default
'horizontal'
step number 1
- Name
- Description
The granularity with which the slider can step through values. The
minprop serves as the origin for the valid values.- Type
number- Default
1
largeStep number 10
- Name
- Description
The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.
- Type
number- Default
10
thumbAlignment SliderThumbAlignment 'center'
- Name
- Description
How the thumb(s) are aligned relative to
Slider.Controlwhen the value is atminormax.edge-client-onlymatchesedgeafter the client measures the thumb.- Type
SliderThumbAlignment- Default
'center'
thumbCollisionBehavior SliderThumbCollisionBehavior 'push'
- Description
How thumbs behave when they collide during pointer interactions.
- Type
SliderThumbCollisionBehavior- Default
'push'
value SliderValue —
- Name
- Description
The value of the slider. For range sliders, provide an array with one value per thumb.
bind:valueshares it with the parent.- Type
SliderValue- Binding
bind:value
onValueChange function —
- Name
- Type
(value: SliderValue, eventDetails: SliderChangeEventDetails) => void
onValueCommitted function —
- Name
- Type
(value: SliderValue, eventDetails: SliderCommitEventDetails) => void
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]> —
- Name
- Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]>
activeThumbIndex number
- Name
activeThumbIndex- Description
The index of the active thumb.
- Type
number
disabled boolean
- Name
disabled- Description
Whether the component should ignore user interaction.
- Type
boolean
dragging boolean
- Name
dragging- Description
Whether the thumb is currently being dragged.
- Type
boolean
max number
- Name
max- Description
The maximum value.
- Type
number
min number
- Name
min- Description
The minimum value.
- Type
number
minStepsBetweenValues number
- Name
minStepsBetweenValues- Description
The minimum steps between values in a range slider.
- Type
number
orientation SliderOrientation
- Name
orientation- Description
The component orientation.
- Type
SliderOrientation
step number
- Name
step- Description
The step increment of the slider when incrementing or decrementing. It will snap to multiples of this value. Decimal values are supported.
- Type
number
values readonly number[]
- Name
values- Description
The raw number value of the slider.
- Type
readonly number[]
touched boolean
- Name
touched- Description
Whether the field has been touched.
- Type
boolean
dirty boolean
- Name
dirty- Description
Whether the field value has changed from its initial value.
- Type
boolean
valid boolean | null
- Name
valid- Description
Whether the field is valid.
nullmeans validity is not known yet.- Type
boolean | null
filled boolean
- Name
filled- Description
Whether the field has a value.
- Type
boolean
focused boolean
- Name
focused- Description
Whether the field is focused.
- Type
boolean
data-dragging
data-orientation
data-disabled
data-valid
data-invalid
data-dirty
data-touched
data-focused
Label
An accessible label that is automatically associated with the slider thumbs. Renders a <div> element.
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]> —
- Name
- Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]>
Value
Displays the current value of the slider as text. Renders an <output> element.
aria-live "off" | "assertive" | "polite" | null 'off'
- Name
- Description
Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.
- Type
"off" | "assertive" | "polite" | null- Default
'off'
children Snippet<[formattedValues: readonly string[], values: readonly number[]]> —
- Name
- Description
Custom value text. Receives the formatted strings and the raw numbers. Omit it to show the formatted values joined with an en dash.
- Type
Snippet<[formattedValues: readonly string[], values: readonly number[]]>
render Snippet<[props: HTMLAttributes<HTMLOutputElement>, state: SliderRootState, children: Snippet | undefined]> —
- Name
- Type
Snippet<[props: HTMLAttributes<HTMLOutputElement>, state: SliderRootState, children: Snippet | undefined]>
data-dragging
data-orientation
data-disabled
data-valid
data-invalid
data-dirty
data-touched
data-focused
Control
The clickable, interactive part of the slider. Renders a <div> element.
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]> —
- Name
- Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]>
data-dragging
data-orientation
data-disabled
data-valid
data-invalid
data-dirty
data-touched
data-focused
Track
Contains the slider indicator and represents the entire range of the slider. Renders a <div> element.
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]> —
- Name
- Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]>
data-dragging
data-orientation
data-disabled
data-valid
data-invalid
data-dirty
data-touched
data-focused
Indicator
Visualizes the current value of the slider. Renders a <div> element.
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]> —
- Name
- Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]>
data-dragging
data-orientation
data-disabled
data-valid
data-invalid
data-dirty
data-touched
data-focused
Thumb
The draggable part of the slider at the tip of the indicator. Renders a <div> element and a nested <input type="range">.
disabled boolean | null false
- Name
- Description
Whether the thumb should ignore user interaction.
- Type
boolean | null- Default
false
aria-valuetext string | undefined —
- Name
- Description
Forwarded to the nested input's
aria-valuetext. Ignored whengetAriaValueTextis set.- Type
string | undefined
getAriaLabel function | null —
- Name
- Description
Returns the
aria-labelof the nested input.- Type
((index: number) => string) | null
getAriaValueText function | null —
- Name
- Description
Returns the
aria-valuetextof the nested input.- Type
((formattedValue: string, value: number, index: number) => string) | null
index number —
- Name
- Description
The index of the thumb in
valueordefaultValue. Required for server-rendered range sliders.- Type
number
onblur function —
- Name
- Description
Blur handler forwarded to the nested input.
- Type
(event: FocusEvent & { currentTarget: EventTarget & HTMLInputElement }) => void
onfocus function —
- Name
- Description
Focus handler forwarded to the nested input.
- Type
(event: FocusEvent & { currentTarget: EventTarget & HTMLInputElement }) => void
onkeydown function —
- Name
- Description
Keydown handler forwarded to the nested input.
- Type
(event: KeyboardEvent & { currentTarget: EventTarget & HTMLInputElement }) => void
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]> —
- Name
- Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SliderRootState, children: Snippet | undefined]>