Range Examples
The examples below assume that you have imported the component and set up the theme. For a single thumb, use the much smaller sv-slider.
Basic
Let users pick a range between two values. value sets both thumb positions, separated by a space.
<div class="range-basic"> <sv-range aria-label="Price" step="1" value="25 75"></sv-range></div>
<style> .range-basic { display: grid; gap: 1em; inline-size: min(100%, 22rem); margin-inline: auto;
sv-range[vertical] { justify-self: center; block-size: 12em; } }</style>Spacing
Keep neighboring thumbs within a minimum and maximum distance of each other. min-steps-between and max-steps-between limit the gap in steps, and push-thumbs lets a thumb push its neighbor.
<div class="range-spacing"> <sv-range aria-label="Price" max-steps-between="60" min-steps-between="10" push-thumbs step="1" value="25 75" ></sv-range></div>
<style> .range-spacing { display: grid; inline-size: min(100%, 22rem); margin-inline: auto; }</style>Thumbs
Select several values with more than two thumbs. A list in value sets the thumbs, and the thumb-label-{n} slots name them.
<div class="range-container"> <label for="multi-thumb">Multiple Thumbs:</label> <sv-range id="multi-thumb" value="10 50 90"> <span slot="thumb-label-1">Low</span> <span slot="thumb-label-2">Mid</span> <span slot="thumb-label-3">High</span> </sv-range></div>
<style> .range-container { display: flex; flex-direction: column; gap: 1em; }</style>Labels
Name the key values in the tooltips, like "Room" and "Body" for a temperature range, and show the number between them. show-tooltip="always" keeps the default tooltips open, and each one shows the <datalist> option label when there is one.
<!-- eslint-disable html/use-baseline --><div class="range-labels"> <label for="range-temperature">Temperature</label>
<sv-range id="range-temperature" max="100" min="-10" show-tooltip="always" value="20 37"> <datalist> <option label="Freezing" value="0"></option> <option label="Room" value="20"></option> <option label="Body" value="37"></option> <option label="Hot bath" value="45"></option> <option label="Boiling" value="100"></option> </datalist> </sv-range></div>
<style> .range-labels { display: grid; gap: 3em; inline-size: min(100%, 22rem); margin-inline: auto; }</style>Tooltip Slot
Show a unit next to each value in the tooltips, like a currency sign for a price range. Each tooltip-{n} slot replaces the default tooltip of its thumb, and a data-sv-range-value element inside it shows the value of that thumb.
<div class="range-tooltip-slot"> <label for="range-price">Price</label>
<sv-range id="range-price" max="500" show-tooltip="always" step="10" value="100 300"> <span aria-hidden="true" slot="tooltip-1"> $ <span data-sv-range-value></span> </span> <span aria-hidden="true" slot="tooltip-2"> $ <span data-sv-range-value></span> </span> </sv-range></div>
<style> .range-tooltip-slot { display: grid; gap: 3em; inline-size: min(100%, 22rem); margin-inline: auto; }</style>Segments
Style each stretch between two thumbs on its own, like the work and break times of a shift. Each stretch is a fill-{n} part, and setValue() with a list and animate: true moves all thumbs in one animation.
This animation will not play for you because your system is set to reduce motion.
<div class="range-segments"> <label for="range-shift">Shift</label>
<sv-range id="range-shift" class="shift-slider" max="22" min="6" min-steps-between="3" push-thumbs show-tooltip step="0.5" value="8 12 13.5 17" > <span aria-label="Shift start" slot="thumb-label-1"></span> <span aria-label="Break start" slot="thumb-label-2"></span> <span aria-label="Break end" slot="thumb-label-3"></span> <span aria-label="Shift end" slot="thumb-label-4"></span> </sv-range>
<div class="shift-presets"> <button type="button" class="btn" data-shift="6 9 10.5 14">Early</button> <button type="button" class="btn" data-shift="8 12 13.5 17">Day</button> <button type="button" class="btn" data-shift="14 17 18.5 22">Late</button> </div></div>
<script type="application/x-typescript" module> const example = document.querySelector<HTMLElement>(".range-segments")!; const slider = example.querySelector<RangeSlider>(".shift-slider")!;
for (const button of example.querySelectorAll<HTMLButtonElement>("[data-shift]")) { button.addEventListener("click", () => { const shiftValues = button.dataset.shift!.split(" ").map(Number); slider.setValue({ value: shiftValues, animate: true }); }); }</script>
<style> .range-segments { display: grid; gap: 1em; inline-size: min(100%, 26rem); margin-inline: auto; }
.shift-slider { --sv-slider-thumb-sz: 1em; --sv-slider-track-thickness: 0.7em;
&::part(fill-1), &::part(fill-3) { background: #22c55e; }
&::part(fill-2) { background: #f97316; } }
.shift-presets { display: flex; gap: 0.5em;
.btn { flex: 1; } }</style>