Slider
Examples
Native form submission and spoken value
name submits the current value. ariaValueText replaces the raw number for
assistive technology when the digits do not carry the meaning.
Documentation
A range slider input for selecting a numeric value within min/max bounds. The value prop is bindable and represents the current position of the slider thumb. The track fills with an active color from the left edge to the thumb position. An optional value label displays the current numeric value beside the slider. Supports step for snapping to intervals and disabled to prevent interaction.
Usage
<script>
import { Slider } from '@juspay/svelte-ui-components';
</script>
<Slider value={50} />
In a form, with a spoken value
<form onsubmit={handleSubmit}>
<Slider bind:value name="volume" ariaLabel="Volume" labelFormatter={(v) => `${v}%`} />
<button type="submit">Save</button>
</form>
The fill is clamped to 0–100% for values outside the range, and paints nothing for an empty, reversed or non-finite range. The value itself is never rewritten: a slider handed a number outside its own bounds still reports that number.
Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
| value | number |
No | 0 |
Bindable. The current numeric value of the slider. Must be between min and max. Two-way bound to the underlying range input. |
| min | number |
No | 0 |
The minimum allowed value. Defines the left edge of the slider track. |
| max | number |
No | 100 |
The maximum allowed value. Defines the right edge of the slider track. |
| step | number |
No | 1 |
The increment between selectable values. The slider snaps to multiples of this value between min and max. |
| disabled | boolean |
No | false |
Whether the slider is disabled. When true, the slider is visually dimmed, the thumb cannot be dragged, and no events fire. |
| showValue | boolean |
No | false |
Whether to display the current numeric value as a label next to the slider track. |
| labelFormatter | (value: number) => string |
No | - |
Formats the displayed value label. Called with the current numeric value and returns a string. Falls back to String(value) when absent. |
| ariaLabel | string |
No | - |
Names the range input for assistive tech. A bare slider announces only its value, so a control whose purpose is not carried by nearby visible text needs this. |
| ariaLabelledby | string |
No | - |
Ids of the elements that name the range input, applied as aria-labelledby. Prefer this when the name is already visible on screen. ariaLabel wins if both are set. |
| testId | string |
No | - |
Value for the data-pw attribute on the range input, used for end-to-end testing selectors. |
| classes | string |
No | - |
CSS class string applied to the component's top-level element. Useful for theming — define classes with CSS variable overrides and pass them to create variant styles. |
| ariaValueText | string |
No | undefined |
Spoken in place of the raw number when the digits do not carry the meaning. Falls back to labelFormatter(value) when that is given, and is omitted when neither is. An explicit empty string is honoured. |
| name | string |
No | undefined |
Submits the current value under this name. Omitted while disabled. |
| form | string |
No | undefined |
id of a form elsewhere in the same document. Unavailable through <sui-slider>, whose input sits in a shadow root. |
Events
| Event | Type | Description |
|---|---|---|
| oninput | (value: number) => void |
Fires continuously as the user drags the slider thumb. Receives the current numeric value at each position during the drag. Use this for live preview updates. |
| onchange | (value: number) => void |
Fires when the user releases the slider thumb after dragging, or when a discrete value change completes (e.g., keyboard arrow keys). Receives the final selected numeric value. Use this for committing the value. |
CSS Variables
Override these custom properties to theme the component.
| Variable | Default | CSS Property | Description |
|---|---|---|---|
--slider-track |
(two-stop fill gradient) | background | Overrides the entire track background. Use for custom gradients (e.g., a rainbow hue gradient for color pickers). When set, --slider-track-active-color and --slider-track-background are ignored. |
--slider-container-width |
100% |
width | Width of the slider container element. |
--slider-container-padding |
4px 0 |
padding | Padding around the slider container. |
--slider-track-height |
6px |
height | Height (thickness) of the slider track. |
--slider-track-background |
#e0e0e0 |
background | Background color of the unfilled portion of the track (right of thumb). |
--slider-track-border-radius |
3px |
border-radius | Corner rounding of the slider track. |
--slider-track-active-color |
#2196f3 |
background | Color of the filled portion of the track (left of thumb). |
--slider-thumb-size |
20px |
width, height | Width and height of the draggable thumb. |
--slider-thumb-background |
#ffffff |
background | Background color of the thumb. |
--slider-thumb-border |
2px solid #2196f3 |
border | Border of the thumb. |
--slider-thumb-border-radius |
50% |
border-radius | Corner rounding of the thumb. Use 50% for a circle. |
--slider-thumb-shadow |
0 1px 3px rgba(0, 0, 0, 0.2) |
box-shadow | Box shadow around the thumb for depth. |
--slider-thumb-opacity |
1 |
opacity | Controls the opacity of the slider thumb. |
--slider-thumb-hover-opacity |
var(--slider-thumb-opacity, 1) |
opacity | Overrides thumb opacity on hover. Falls back to --slider-thumb-opacity (itself defaulting to 1) so only one variable is needed when the hover and resting states match. |
--slider-thumb-hover-scale |
1.15 |
transform: scale() | Scale factor applied to the thumb on hover for visual feedback. |
--slider-focus-ring |
2px solid #2196f3 |
outline | Outline shown around the thumb when it receives keyboard focus (focus-visible). |
--slider-disabled-opacity |
0.5 |
opacity | Opacity of the entire slider when disabled. |
--slider-disabled-cursor |
not-allowed |
cursor | Cursor shown when hovering the disabled slider. |
--slider-value-font-size |
14px |
font-size | Font size of the value label text. |
--slider-value-color |
#333333 |
color | Color of the value label text. |
--slider-value-font-weight |
500 |
font-weight | Font weight of the value label text. |
--slider-transition |
background 0.2s ease |
transition | Transition applied to the track background for smooth fill changes. |
--slider-thumb-transition-duration |
0.15s |
transition | Duration of the thumb's transform/opacity transition. Falls back through --motion-duration. |
--slider-thumb-transition-easing |
ease |
transition | Easing curve of the thumb's transform/opacity transition. Falls back through --motion-easing. |
Web Component
Tag: <sui-slider>
<sui-slider value="50" min="0" max="100" step="1" show-value aria-label="Volume"></sui-slider>
Name the control with the aria-label or aria-labelledby attribute, exactly as
above. Set from JavaScript, the property names are sliderAriaLabel and
sliderAriaLabelledby:
const slider = document.querySelector('sui-slider');
slider.sliderAriaLabel = 'Volume'; // sets the component prop
slider.ariaLabel = 'Volume'; // sets the platform's own ARIAMixin property
ARIAMixin already defines ariaLabel and ariaLabelledby on every HTMLElement.
Declaring them here would replace the platform's accessors, so the element takes the
prefixed names instead — the same collision the 4.0.0 renames avoided elsewhere. The
attributes are unaffected.
oninput and onchange are JS-property callbacks only (slider.oninput = (value) => ...,
slider.onchange = (value) => ...) and do NOT dispatch a matching synthetic DOM event:
input and change are already HTMLElement's own native events, so adding a
same-named synthetic one under those names would risk double-delivering to a
slider.addEventListener('input'/'change', ...) listener. Use the JS property to read
the numeric value.
aria-labelledby on the element is resolved, not forwarded
<sui-slider> renders its range input inside a shadow root, and ARIA id references do
not cross a shadow boundary — an aria-labelledby pointing at an element in your page
cannot name something inside the element's shadow root. Passing the id straight through
would leave the slider with no accessible name at all.
So the element reads the referenced element(s) from your document and applies the text
as aria-label on the input instead. Referencing a visible label works:
<span id="volume-label">Volume</span> <sui-slider aria-labelledby="volume-label"></sui-slider>
The one difference from the Svelte component, where the reference resolves natively: the
name is copied when it resolves, not bound. Editing the label element's text later
does not update the slider's name — re-set aria-labelledby (or use aria-label) if the
name changes. aria-label still wins when both are set.