Slider

Pick a number, or a range, by dragging.

Hourly rate (USD)

<Slider.Root defaultValue={50} />
<Slider.Root defaultValue={[35, 65]} min={20} max={100} />

An array value gives you two thumbs and a range. Slider.Value renders the current value as text next to it.

API

Slider.Root

PropTypeDefault
classNamestring | ((state: SliderRootState) => string | undefined)CSS class applied to the element, or a function that returns a class based on the component's state.
defaultValuenumber | readonly number[]The uncontrolled value of the slider when it's initially rendered. To render a controlled slider, use the value prop instead.
disabledbooleanWhether the slider should ignore user interaction.
formstringIdentifies the form that owns the slider inputs. Useful when the slider is rendered outside the form.
formatNumberFormatOptionsOptions to format the input value.
largeStepnumberThe granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down.
localeLocalesArgumentThe locale used by Intl.NumberFormat when formatting the value. Defaults to the user's runtime locale.
maxnumber100The maximum allowed value of the slider. Should not be equal to min.
minnumber0The minimum allowed value of the slider. Should not be equal to max.
minStepsBetweenValuesnumberThe minimum steps between values in a range slider.
namestringIdentifies the field when a form is submitted.
onValueChange((value: number | readonly number[], eventDetails: SliderRootChangeEventDetails) => 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). The eventDetails.reason indicates what triggered the change:
onValueCommitted((value: number | readonly number[], eventDetails: SliderRootCommitEventDetails) => void)Callback function that is fired when a value change is committed. Does not fire if the value did not change, or if the change was canceled. Warning: This is a generic event, not a change event. The eventDetails.reason indicates what triggered the commit:
orientationOrientationThe component orientation.
renderComponentRenderFn<HTMLProps, SliderRootState> | ReactElement<unknown, string | JSXElementConstructor<any>>Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
stepnumberThe 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.
styleCSSProperties | ((state: SliderRootState) => CSSProperties | undefined)Style applied to the element, or a function that returns a style object based on the component's state.
thumbAlignment"center" | "edge" | "edge-client-only"How the thumb(s) are aligned relative to Slider.Control when the value is at min or max:
thumbCollisionBehavior"none" | "push" | "swap"Controls how thumbs behave when they collide during pointer interactions.
valuenumber | readonly number[]The value of the slider. For ranged sliders, provide an array with two values.

Plus the DOM props of the element it renders. Source: slider/components/slider-root.tsx.

Slider.Value

PropTypeDefault
children((formattedValues: readonly string[], values: readonly number[]) => ReactNode) | null
classNamestring | ((state: SliderValueState) => string | undefined)CSS class applied to the element, or a function that returns a class based on the component's state.
renderComponentRenderFn<HTMLProps, SliderValueState> | ReactElement<unknown, string | JSXElementConstructor<any>>Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: SliderValueState) => CSSProperties | undefined)Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: slider/components/slider-value.tsx.