Skip to main content

A slider for picking a value, or a range of values, between a minimum and a maximum.

30

Read more about installing Components and Primitives.

Render a slider.thumb for each end of the range, with index 0 and 1, and pass two numbers as defaultValue. minStepsBetweenThumbs="10" keeps the thumbs of the price range at least 10 steps apart. In a form, end the name with [] (price[]) for PHP to receive both values.

25 - 75

Add slider.marker elements inside a slider.markerGroup to show labeled ticks along the track.

40

Set disabled="{true}" to block interaction with the slider.

50

Pair the slider with a number input for precise entry: dragging the thumb updates the number, and typing a number moves the thumb. Both are mounted by hand (autoMount="{false}" with a fixed rootId, see Mount one instance yourself) so the entry file can connect them.

Wrap the slider in ui:field.root to pass name, disabled and invalid to the thumb. The demo is a donation amount picker with marks at common amounts.

$ 25
Choose an amount to support this event - every contribution helps.

Nest slider.draggingIndicator inside a slider.thumb to show the current value in a small tooltip while that thumb is dragged.

50

Set step to a fraction like 0.01 for decimal precision, for example for prices or ratings.

7.98

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

Contains every part of the slider. Renders a <div> element.

NameDescriptionRequiredDefault
disabledboolean
Whether the slider is disabled.
No
-
readOnlyboolean
Whether the slider is read-only.
No
-
invalidboolean
Whether the slider is invalid.
No
-
namestring
The name associated with each slider thumb (when used in a form).
No
-
formstring
The associate form of the underlying hidden input elements.
No
-
defaultValuefloat|integer|float[]|integer[]
The initial value of the slider when rendered - a single number for one thumb, or a list of numbers (one per thumb) for a range. Use when you don't need to control the value of the slider.
No
-
minfloat
The minimum value of the slider.
No
0
maxfloat
The maximum value of the slider.
No
100
stepfloat
The step value of the slider.
No
1
largeStepfloat
The step value of the slider when the `Shift` key is held, or the `PageUp`/`PageDown` keys are used. Defaults to `10 * step`.
No
-
minStepsBetweenThumbsfloat
The minimum permitted steps between multiple thumbs. `minStepsBetweenThumbs * step` reflects the gap between the thumbs.
No
0
orientationEnum\Orientation
The orientation of the slider.
No
Horizontal
originEnum\SliderOrigin
The origin of the slider range. The track is filled from the origin to the thumb for single values. `start` is useful when the value represents an absolute value, `center` when it represents an offset (relative), and `end` when it represents an offset from the end.
No
Start
thumbAlignmentEnum\SliderThumbAlignment
The alignment of the slider thumb relative to the track. `center` lets the thumb extend beyond the bounds of the track, `contain` keeps it within the track's bounds.
No
Contain
thumbSizearray
The slider thumb dimensions, with a `width` and `height` key.
No
-
thumbCollisionBehaviorEnum\SliderThumbCollisionBehavior
Controls how thumbs behave when they collide during pointer interactions. `none` keeps thumbs from moving past each other, `push` makes them push each other, `swap` makes them swap places.
No
None
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
providerstring
The `id` of the `.provider` this root takes its `rootId` and props from.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-root<uid>
data-disabledPresent when disabled
data-orientationThe orientation of the slider
data-draggingPresent when in the dragging state
data-invalidPresent when invalid
data-focusPresent when focused

Renders an accessible label for the slider. Renders a <label> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-label<uid>
data-disabledPresent when disabled
data-orientationThe orientation of the label
data-invalidPresent when invalid
data-draggingPresent when in the dragging state
data-focusPresent when focused

Displays a textual representation of the current value. Renders a <span> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-value-text<uid>
data-disabledPresent when disabled
data-orientationThe orientation of the valuetext
data-invalidPresent when invalid
data-focusPresent when focused

Wraps the track and thumbs, and handles pointer interaction with the track. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-control<uid>
data-draggingPresent when in the dragging state
data-disabledPresent when disabled
data-orientationThe orientation of the control
data-invalidPresent when invalid
data-focusPresent when focused

Renders the full length of the slider's track. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-track<uid>
data-disabledPresent when disabled
data-invalidPresent when invalid
data-draggingPresent when in the dragging state
data-orientationThe orientation of the track
data-focusPresent when focused

Renders the filled portion of the track between the origin and the thumb(s). Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-range<uid>
data-draggingPresent when in the dragging state
data-focusPresent when focused
data-invalidPresent when invalid
data-disabledPresent when disabled
data-orientationThe orientation of the range

Renders a draggable handle for one value. Takes an index prop to identify which value it controls. Renders a <div> element.

NameDescriptionRequiredDefault
indexinteger
The index of the thumb. Use a distinct index per `slider.thumb` for a range slider with multiple thumbs.
No
0
namestring
The name of the thumb. Defaults to the root `name`.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-thumb<uid>
data-indexThe index of the item
data-name
data-disabledPresent when disabled
data-orientationThe orientation of the thumb
data-focusPresent when focused
data-draggingPresent when in the dragging state

Provides a native input for form submission, nested inside a slider.thumb. Renders an <input> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Groups the marks/ticks rendered along the track. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-marker-group<uid>
data-orientationThe orientation of the markergroup

Renders a single mark/tick at a given value. Renders a <div> element.

NameDescriptionRequiredDefault
valuefloat
The value along the track at which to render the marker.
Yes
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-marker<uid>
data-orientationThe orientation of the marker
data-valueThe value of the item
data-disabledPresent when disabled
data-state"under-value" | "over-value" | "at-value"

Displays the current value while its thumb is being dragged. Nested inside a slider.thumb, whose index it follows automatically. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-slider-dragging-indicator<uid>
data-orientationThe orientation of the draggingindicator
data-state"open" | "closed"
NameTypeDescription
valuenumber[]The value of the slider.
draggingbooleanWhether the slider is being dragged.
focusedbooleanWhether the slider is focused.
setValue(value: number[]) => voidFunction to set the value of the slider.
getThumbValue(index: number) => numberReturns the value of the thumb at the given index.
setThumbValue(index: number, value: number) => voidSets the value of the thumb at the given index.
getValuePercent(value: number) => numberReturns the percent of the thumb at the given index.
getPercentValue(percent: number) => numberReturns the value of the thumb at the given percent.
getThumbPercent(index: number) => numberReturns the percent of the thumb at the given index.
setThumbPercent(index: number, percent: number) => voidSets the percent of the thumb at the given index.
getThumbMin(index: number) => numberReturns the min value of the thumb at the given index.
getThumbMax(index: number) => numberReturns the max value of the thumb at the given index.
increment(index: number) => voidFunction to increment the value of the slider at the given index.
decrement(index: number) => voidFunction to decrement the value of the slider at the given index.
focusVoidFunctionFunction to focus the slider. This focuses the first thumb.
getRootState() => RootStateReturns the state of the slider
getThumbState(props: ThumbProps) => ThumbStateReturns the state of a specific thumb
getMarkerState(props: MarkerProps) => MarkerStateReturns the state of a specific marker
KeyDescription
ArrowRightIncrements the slider based on defined step
ArrowLeftDecrements the slider based on defined step
ArrowUpIncreases the value by the step amount.
ArrowDownDecreases the value by the step amount.
PageUpIncreases the value by the largeStep amount.
PageDownDecreases the value by the largeStep amount.
Shift + ArrowUpIncreases the value by the largeStep amount.
Shift + ArrowDownDecreases the value by the largeStep amount.
HomeSets the value to its minimum.
EndSets the value to its maximum.