Skip to main content

An input for selecting a value, or a range of values, from a given range.

30
typo3 ui:add slider

Read more about installing Components and Primitives.

Use two thumbs to let users pick a range of values.

25 - 75

Render slider.marker elements to show ticks - with a label - along the track.

40

Prevent the slider from being interacted with.

50

Pair the slider with a number-input for precise entry, keeping both in sync by updating one whenever the other changes. Both are mounted as independent, hydration-controlled instances (controlled="{true}" + a fixed rootId) so a custom entry file can wire them together, the same pattern Combobox's custom filter example uses. Both components' own onValueChange call into one shared setValue() function instead of writing to each other directly, so there's a single guard - skip if it's already the current value - rather than a syncing flag guessing which call is the "real" one.

Wrap the slider in ui:field.root to get label association and name/disabled/invalid state propagated to the thumb automatically - a donation amount picker, with marks for common preset amounts.

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

Nest slider.draggingIndicator inside a slider.thumb to show its current value in a small tooltip while it's being dragged - it's hidden the rest of the time.

50

Set step to a fraction (e.g. 0.01) to get fine-grained, decimal precision instead of whole numbers - useful whenever the value represents something more precise than an integer count.

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.

slider.root

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|array
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
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
[]
controlledboolean
If true, the component is meant to be initialized manually inside another component
No
false
classstring
The CSS class(es) to be applied to the component.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-partroot
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

slider.label

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-partlabel
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

slider.valueText

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-partvalue-text
data-disabledPresent when disabled
data-orientationThe orientation of the valuetext
data-invalidPresent when invalid
data-focusPresent when focused

slider.control

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-partcontrol
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

slider.track

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-parttrack
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

slider.range

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-partrange
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

slider.thumb

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
-
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-partthumb
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

slider.hiddenInput

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

slider.markerGroup

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-partmarker-group
data-orientationThe orientation of the markergroup

slider.marker

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
-
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-partmarker
data-orientationThe orientation of the marker
data-valueThe value of the item
data-disabledPresent when disabled
data-state

slider.draggingIndicator

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
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeslider
data-partdragging-indicator
data-orientationThe orientation of the draggingindicator
data-state"open" | "closed"

Machine JavaScript API

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.

Accessibility

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.
<primitives:slider.root>
    <primitives:slider.label />
    <primitives:slider.valueText />
    <primitives:slider.control>
        <primitives:slider.track>
            <primitives:slider.range />
        </primitives:slider.track>
        <primitives:slider.thumb index="0">
            <primitives:slider.hiddenInput />
        </primitives:slider.thumb>
        <primitives:slider.markerGroup>
            <primitives:slider.marker value="25" />
        </primitives:slider.markerGroup>
    </primitives:slider.control>
</primitives:slider.root>