Area Slider Examples
The examples below assume that you have imported the component and set up the theme.
Basic
Add a two-axis slider that picks a point in an area and shows its x and y values. value sets the start point as the x and y values separated by a space, valueXY reads them, and the valuechange event updates the readout.
<div class="area-slider-basic"> <sv-area-slider aria-label="Position" value="0 0"></sv-area-slider> <output></output></div>
<script type="application/x-typescript" module> const slider = document.querySelector<AreaSlider>(".area-slider-basic sv-area-slider")!; const valueOutput = document.querySelector<HTMLOutputElement>(".area-slider-basic output")!;
updateValueOutput(); slider.addEventListener("valuechange", updateValueOutput);
function updateValueOutput() { const [x, y] = slider.valueXY; valueOutput.value = `x ${x}, y ${y}`; }</script>
<style> .area-slider-basic { display: grid; gap: 0.75em; place-content: center; justify-items: center;
output { font-variant-numeric: tabular-nums; } }</style>Markers
Draw grid lines at chosen values, and snap the thumb to them. A <datalist> in each of the markers-x and markers-y slots holds <option> elements, and each option adds a marker at its value.
<!-- eslint-disable html/use-baseline --><div class="area-slider-markers"> <sv-area-slider aria-label="Position" value="40 60"> <datalist slot="markers-x"></datalist> <datalist slot="markers-y"></datalist> </sv-area-slider> <output></output></div>
<script type="application/x-typescript" module> const slider = document.querySelector<AreaSlider>(".area-slider-markers sv-area-slider")!; const valueOutput = document.querySelector<HTMLOutputElement>(".area-slider-markers output")!;
for (const dataList of slider.querySelectorAll("datalist")) { for (let value = 25; value < 100; value += 25) { dataList.append(new Option(String(value), String(value))); } }
const updateValueOutput = () => { const [x, y] = slider.valueXY; valueOutput.value = `x ${x}, y ${y}`; };
updateValueOutput(); slider.addEventListener("valuechange", updateValueOutput);</script>
<style> .area-slider-markers { display: grid; gap: 1.25em; place-content: center; justify-items: center;
output { font-variant-numeric: tabular-nums; } }</style>Follow Shape
Keep the thumb inside the rounded corners of the area. follow-shape fits the thumb path to the area's border radius.
<!-- eslint-disable html/use-baseline --><div class="area-slider-follow-shape"> <sv-area-slider aria-label="Position" follow-shape value="100 100"> <datalist slot="markers-x"> <option value="25"></option> <option value="50"></option> <option value="75"></option> </datalist> <datalist slot="markers-y"> <option value="25"></option> <option value="50"></option> <option value="75"></option> </datalist> </sv-area-slider> <output></output></div>
<script type="application/x-typescript" module> const slider = document.querySelector<AreaSlider>(".area-slider-follow-shape sv-area-slider")!; const valueOutput = document.querySelector<HTMLOutputElement>( ".area-slider-follow-shape output" )!;
const updateValueOutput = () => { const [x, y] = slider.valueXY; valueOutput.value = `x ${x}, y ${y}`; };
updateValueOutput(); slider.addEventListener("valuechange", updateValueOutput);</script>
<style> .area-slider-follow-shape { display: grid; gap: 0.75em; justify-items: center;
output { font-variant-numeric: tabular-nums; } }</style>Warp Background
Keep each point of a background under the value it shows when the area is rounded. warp-background bends the content of the background slot with the shape that follow-shape sets. At the default border radius the warp is too small to see, and a larger --sv-area-slider-bdr-rad shows it.
<div class="area-slider-warp-background"> <sv-area-slider aria-label="Position" follow-shape value="80 80" warp-background> <div slot="background"></div> </sv-area-slider> <output></output></div>
<script type="application/x-typescript" module> const slider = document.querySelector<AreaSlider>(".area-slider-warp-background sv-area-slider")!; const valueOutput = document.querySelector<HTMLOutputElement>( ".area-slider-warp-background output" )!;
updateValueOutput(); slider.addEventListener("valuechange", updateValueOutput);
function updateValueOutput() { const [x, y] = slider.valueXY; valueOutput.value = `x ${x}, y ${y}`; }</script>
<style> .area-slider-warp-background { display: grid; gap: 0.75em; justify-items: center;
[slot="background"] { --ring-color: var(--sv-accent, AccentColor); --base-color: var(--sv-gray-6, Canvas); --ring-80: color-mix(in oklch, var(--ring-color) 80%, var(--base-color)); --ring-60: color-mix(in oklch, var(--ring-color) 60%, var(--base-color)); --ring-40: color-mix(in oklch, var(--ring-color) 40%, var(--base-color)); --ring-20: color-mix(in oklch, var(--ring-color) 20%, var(--base-color));
block-size: 100%; background: linear-gradient(var(--ring-color) 0 0) center / 20% 20% no-repeat, linear-gradient(var(--ring-80) 0 0) center / 40% 40% no-repeat, linear-gradient(var(--ring-60) 0 0) center / 60% 60% no-repeat, linear-gradient(var(--ring-40) 0 0) center / 80% 80% no-repeat, var(--ring-20); }
output { font-variant-numeric: tabular-nums; } }</style>