Color Slider Examples
The examples below assume that you have imported the component and set up the theme.
Basic
Let the user pick one channel of a color, like the hue. value holds the hue, and the valuechange event updates the readout.
The controls show the channel values of each color-space.
--active
<div class="color-slider-basic"> <label for="color-slider-basic">Color Slider</label> <sv-color-slider id="color-slider-basic" style="--sv-slider-marker-clr: transparent" value="217" ></sv-color-slider> <output></output></div>
<script type="application/x-typescript" module> const colorSlider = document.querySelector<ColorSlider>("#color-slider-basic")!; const valueOutput = document.querySelector<HTMLOutputElement>(".color-slider-basic output")!;
updateValueOutput(); colorSlider.addEventListener("valuechange", updateValueOutput);
function updateValueOutput() { valueOutput.value = `value="${colorSlider.value}"`; }</script>
<style> .color-slider-basic { display: grid; gap: 0.5em; justify-items: center;
label { font-weight: 600; }
sv-color-slider { inline-size: min(100%, 20em); }
sv-color-slider[vertical] { inline-size: auto; block-size: 12em; }
output { font-family: monospace; font-size: 0.85em; color: var(--sv-gray-3); } }</style>