Slider
Choose a number or range by moving one or more thumbs.
Anatomy#
Usage#
Use Slider when a numeric value or range is best chosen spatially. Pair it with a labeled numeric field when users need precise text entry. Use NumberInput when the value is typed and stepped rather than dragged. Use BoldSlider for a compact single value with the label and value shown inside the track.
Single values and ranges#
Use a number for one thumb and an array for one thumb per entry, such as an ordered pair for a
range. Values are clamped to min–max (default 0–100), and arrays are sorted. Pair value
with onValueChange for controlled state, or use defaultValue for uncontrolled state; its shape
sets the shape of the value that callbacks receive.
onValueChange fires on every change during a drag, track click, or key press, but not for
programmatic changes to value. Use onValueCommit to react once when the interaction ends, such
as when saving a setting.
Step and markers#
step (default 1) snaps pointer drag and keyboard navigation to multiples of it from min;
step={0} keeps the slider continuous. Set markers to true to draw a tick at each step, or to a
number to draw a tick every that many units without changing how the value snaps.
Value text format#
formatOptions accepts Intl.NumberFormat options and formats each thumb’s raw value (not its
share of the range) for aria-valuetext with the provider locale, as BoldSlider and Progress do. It
does not change the value that callbacks receive.
A percent style multiplies by 100, so pair it with a 0–1 range. BoldSlider also uses
formatOptions for its visible value unless valueLabel is a formatter.
Forms#
Add name for native form submission, or place the slider inside form.Field from
createForm for schema binding. Use standalone Field when
you only need a label and messages.
Custom content#
Pass children to render extra content inside the root after the thumbs. A render function
receives the live value, sorted values, percentages from 0 to 1, dragging state, and the
startEdge where the filled range begins.
Declare the function’s parameter even when you do not use it; a zero-argument function is called as an accessor and is not mounted as a component.
Keyboard interaction#
Arrow keys move by step (default 1); with step={0} they move by 1% of the configured range.
Page-sized movement is approximately 10% of the range and snaps to step when above 0.
Horizontal arrow keys swap in right-to-left layouts, and a reversed vertical slider swaps
↑ and ↓.
| Key | Description |
|---|---|
| → / ↑ | Moves in the increasing direction by one keyboard step. |
| ← / ↓ | Moves in the decreasing direction by one keyboard step. |
| Shift + Arrow | Moves by the page-sized increment. |
| ⇞ / ⇟ | Moves by the page-sized increment. |
| ↖ | Moves the focused thumb to its minimum permitted value. |
| ↘ | Moves the focused thumb to its maximum permitted value. |
Examples#
Controlled#
Control a single numeric value with value and onValueChange.
Range#
Pass an ordered pair for two thumbs. minStepsBetweenThumbs and allowThumbCrossing constrain
whether the thumbs may overlap.
Form#
Place the slider in form.Field so the schema owns the committed number.
Steps and markers#
Set step so drag and keyboard land on increments. Enable markers to draw those ticks on the
track.
API Reference#
Attributes#
data-disableddata-draggingdata-invaliddata-multipledata-readonlydata-requireddata-reverseddata-swipe-ignoredata-emptydata-activedata-focus-visibleProps#
Props for the Slider component. Renders a <div> element by default.