A continuous slider from 0 to 100.
<k-slider value="25"></k-slider>
Use the steps attribute to define specific snap points. The slider will only stop on those values.
<k-slider min="0" max="100" value="50" steps="0,25,50,75,100">Volume</k-slider>
Pass two comma-separated numbers as the value to create a range slider with two handles. The first number is the lower bound and the second is the upper bound. The handles cannot cross each other.
<k-slider value="20,80"></k-slider>
<k-slider value="25,75" steps="0,25,50,75,100">Price Range</k-slider>
Add the vertical attribute to render the slider vertically. Set a height on the element or its container.
<k-slider vertical value="40"></k-slider>
Combine vertical with a comma-separated value for a vertical range slider.
<k-slider vertical value="20,80" steps="0,20,40,60,80,100"></k-slider>
<k-slider value="50" style="
--track_height: 10px;
--fill_background: var(--c_success);
--thumb_size: 28px;
--thumb_background: var(--c_success);
--step_dot_size: 12px;
"></k-slider>
Add the tooltip attribute to show a value tooltip above the handle while dragging. Use the format attribute to control how the value is displayed in the tooltip, change event, and form submission. The pattern 0.00 in the format string is replaced with the numeric value at the matching decimal precision.
<k-slider value="25" min="0" max="100" format="$0.00" tooltip></k-slider>
<k-slider id="jsSlider" value="0" format="0" tooltip></k-slider>
<p>Value: <span id="sliderVal">0</span></p>
<script>
const $jsSlider = document.getElementById('jsSlider');
const $sliderVal = document.getElementById('sliderVal');
$jsSlider.addEventListener('change', (e) => {
$sliderVal.textContent = e.detail.value;
});
</script>
Value: 0
<k-slider id="jsRangeSlider" value="10,90" format="0" tooltip></k-slider>
<p>Range: <span id="rangeDisplay">10 - 90</span></p>
<script>
const $rs = document.getElementById('jsRangeSlider');
const $rd = document.getElementById('rangeDisplay');
$rs.addEventListener('change', (e) => {
const [lo, hi] = e.detail.value.split(',');
$rd.textContent = lo + ' - ' + hi;
});
</script>
Range: 10 - 90
The slider is form-associated. Set a name attribute so it participates in form submission. When a format is set, the submitted value is the formatted string.
<form id="sliderForm">
<k-slider name="volume" value="75" format="0%"></k-slider>
<k-slider name="priceRange" value="20,80" format="$0"></k-slider>
<button type="submit">Submit</button>
</form>
<p>Form Data: <span id="formOutput"></span></p>
<script>
document.getElementById('sliderForm').addEventListener('submit', (e) => {
e.preventDefault();
const fd = new FormData(e.target);
const entries = [...fd.entries()].map(([k, v]) => k + '=' + v);
document.getElementById('formOutput').textContent = entries.join(', ');
});
</script>
Form Data:
The disabled attribute prevents user interaction while displaying the current value.
<k-slider disabled value="40"></k-slider>
new Slider()value: StringThe current value. A single number (e.g. "50") for a standard slider, or two comma-separated numbers (e.g. "20,80") for a range slider. Default is "0". Syncs to value attribute.
name: StringThe form field name. When set inside a <form>, the slider participates in form submission. Syncs to name attribute.
min: NumberThe minimum value of the slider range. Default is 0. Syncs to min attribute.
max: NumberThe maximum value of the slider range. Default is 100. Syncs to max attribute.
steps: StringA comma-separated list of specific values the slider can snap to (e.g. "0,25,50,75,100"). When set, the slider only stops on these values. When not set, the slider is continuous. Syncs to steps attribute.
format: StringA pattern string for formatting the slider value. Applied to the tooltip display, the change event detail.value, and the form submission value. Use 0s as digit placeholders — the number of 0s after the decimal separator controls precision. For example "$0.00" formats 25 as "$25.00". Default is null (raw number). Syncs to format attribute.
tooltip: BooleanWhen true, a tooltip showing the current value appears above the thumb handle during drag. Default is false. Syncs to tooltip attribute.
vertical: BooleanWhen true, the slider renders vertically. Set a height on the element to control the track length. Default is false. Syncs to vertical attribute.
disabled: BooleanWhen true, the slider cannot be changed by user interaction. The element appears at 50% opacity. Syncs to disabled attribute.
setValue(newValue): voidSets the lower value, clamped to min/max and snapped to the nearest step. In range mode, it cannot exceed the upper value.
setUpper(newValue): voidSets the upper value (range mode only), clamped to min/max and snapped to the nearest step. Cannot go below the lower value.
isRange: Boolean (getter)Returns true when the value contains a comma (i.e. two handles are active).
formattedValue: String (getter)Returns the value formatted with the format pattern. For range sliders, both halves are formatted (e.g. "$20.00,$80.00"). Returns the raw value when no format is set.
lower: Number (getter)The numeric lower bound parsed from value.
upper: Number (getter)The numeric upper bound parsed from value. Equals max when not in range mode.
| Variable | Default | Description |
|---|---|---|
--track_height | 6px | Thickness of the track (height when horizontal, width when vertical) |
--track_background | var(--c_border) | Background color of the track |
--track_radius | 99999px | Border radius of the track |
--fill_background | var(--c_primary) | Color of the filled portion |
--thumb_size | 20px | Diameter of the thumb handle(s) |
--thumb_background | var(--c_primary) | Background color of the thumb(s) |
--thumb_border | 2px solid white | Border of the thumb(s) |
--thumb_shadow | 0 1px 3px rgba(0,0,0,.3) | Box shadow of the thumb(s) |
--step_dot_size | 8px | Diameter of step indicator dots |
--step_dot_background | var(--c_bg__alt) | Background of step dots |
--step_dot_border | 1px solid var(--c_border) | Border of step dots |
changeFired when the value changes. The event detail contains { value: String }. When a format is set, the value is formatted (e.g. "$50.00" or "$20.00,$80.00"). Without a format, the raw number string is used (e.g. "50" or "20,80").