Skip to content

Color Group Examples

The examples below assume that you have imported the component and set up the theme.

Basic

Combine color sliders into one color picker that edits every channel of one color. sv-color-group keeps the color and reads it as hex in value, channel picks the channel of each slider, and color-space="rgb" enables the RGB channels.

adaptive paints each slider with the color of the group, and each sv-color-swatch sets a preset color and shows as checked while the group has its color.

<div class="color-group-basic">
<sv-color-group value="#3b82f6">
<div class="preview">
<div class="swatch"></div>
<output></output>
</div>
<label for="color-group-basic-hue">Hue</label>
<sv-color-slider
id="color-group-basic-hue"
adaptive
channel="hue"
thumb-contained
></sv-color-slider>
<label for="color-group-basic-saturation">Saturation</label>
<sv-color-slider
id="color-group-basic-saturation"
adaptive
channel="saturation"
thumb-contained
></sv-color-slider>
<label for="color-group-basic-brightness">Brightness</label>
<sv-color-slider
id="color-group-basic-brightness"
adaptive
channel="brightness"
thumb-contained
></sv-color-slider>
<label for="color-group-basic-red">Red</label>
<sv-color-slider
id="color-group-basic-red"
adaptive
channel="red"
color-space="rgb"
thumb-contained
></sv-color-slider>
<label for="color-group-basic-green">Green</label>
<sv-color-slider
id="color-group-basic-green"
adaptive
channel="green"
color-space="rgb"
thumb-contained
></sv-color-slider>
<label for="color-group-basic-blue">Blue</label>
<sv-color-slider
id="color-group-basic-blue"
adaptive
channel="blue"
color-space="rgb"
thumb-contained
></sv-color-slider>
<label for="color-group-basic-alpha">Alpha</label>
<sv-color-slider
id="color-group-basic-alpha"
adaptive
channel="alpha"
thumb-contained
></sv-color-slider>
<div class="presets" aria-label="Presets" role="radiogroup">
<sv-color-swatch
aria-label="Blue"
name="color-group-basic-preset"
value="#3b82f6"
></sv-color-swatch>
<sv-color-swatch
aria-label="Teal"
name="color-group-basic-preset"
value="#0d9488"
></sv-color-swatch>
<sv-color-swatch
aria-label="Amber"
name="color-group-basic-preset"
value="#d97706"
></sv-color-swatch>
<sv-color-swatch
aria-label="Rose"
name="color-group-basic-preset"
value="#e11d48"
></sv-color-swatch>
</div>
</sv-color-group>
</div>
<script type="application/x-typescript" module>
const wrapper = document.querySelector<HTMLDivElement>(".color-group-basic")!;
const colorGroup = wrapper.querySelector<ColorGroup>("sv-color-group")!;
const valueOutput = wrapper.querySelector<HTMLOutputElement>("output")!;
updateValueOutput();
colorGroup.addEventListener("valuechange", updateValueOutput);
function updateValueOutput() {
valueOutput.value = colorGroup.value;
wrapper.style.setProperty("--color", colorGroup.value);
}
</script>
<style>
.color-group-basic {
--color: #3b82f6;
inline-size: min(100%, 20em);
margin-inline: auto;
sv-color-group {
display: grid;
gap: 0.5em;
}
.preview {
display: flex;
gap: 1em;
align-items: center;
margin-block-end: 0.5em;
}
.swatch {
inline-size: 3em;
block-size: 2em;
background:
linear-gradient(var(--color), var(--color)),
repeating-conic-gradient(#ccc 0 25%, #fff 0 50%) 0 0 / 0.5em 0.5em;
border: 1px solid var(--sv-gray-5);
border-radius: var(--sv-bdr-rad-md);
}
output {
font-family: monospace;
}
label {
font-weight: 600;
}
.presets {
display: flex;
gap: 0.6em;
justify-content: center;
margin-block-start: 0.75em;
}
}
</style>

Areas

Edit the HSV and RGB channels of one color with color areas, two channels in each area. channels on each sv-color-area picks its x and y channels, color-space="rgb" enables the RGB channels, and sv-color-group keeps the areas on the same color.

<div class="color-group-areas">
<sv-color-group value="#3b82f6">
<div class="preview">
<div class="swatch"></div>
<output></output>
</div>
<div class="areas">
<div class="field">
<label for="color-group-areas-saturation-brightness">Saturation and brightness</label>
<sv-color-area
id="color-group-areas-saturation-brightness"
adaptive
channels="saturation brightness"
></sv-color-area>
</div>
<div class="field">
<label for="color-group-areas-hue-saturation">Hue and saturation</label>
<sv-color-area
id="color-group-areas-hue-saturation"
adaptive
channels="hue saturation"
></sv-color-area>
</div>
<div class="field">
<label for="color-group-areas-red-green">Red and green</label>
<sv-color-area
id="color-group-areas-red-green"
adaptive
channels="red green"
color-space="rgb"
></sv-color-area>
</div>
<div class="field">
<label for="color-group-areas-green-blue">Green and blue</label>
<sv-color-area
id="color-group-areas-green-blue"
adaptive
channels="green blue"
color-space="rgb"
></sv-color-area>
</div>
</div>
<div class="presets" aria-label="Presets" role="radiogroup">
<sv-color-swatch
aria-label="Blue"
name="color-group-areas-preset"
value="#3b82f6"
></sv-color-swatch>
<sv-color-swatch
aria-label="Teal"
name="color-group-areas-preset"
value="#0d9488"
></sv-color-swatch>
<sv-color-swatch
aria-label="Amber"
name="color-group-areas-preset"
value="#d97706"
></sv-color-swatch>
<sv-color-swatch
aria-label="Rose"
name="color-group-areas-preset"
value="#e11d48"
></sv-color-swatch>
</div>
</sv-color-group>
</div>
<script type="application/x-typescript" module>
const wrapper = document.querySelector<HTMLDivElement>(".color-group-areas")!;
const colorGroup = wrapper.querySelector<ColorGroup>("sv-color-group")!;
const valueOutput = wrapper.querySelector<HTMLOutputElement>("output")!;
updateValueOutput();
colorGroup.addEventListener("valuechange", updateValueOutput);
function updateValueOutput() {
valueOutput.value = colorGroup.value;
wrapper.style.setProperty("--color", colorGroup.value);
}
</script>
<style>
.color-group-areas {
--color: #3b82f6;
inline-size: min(100%, 24em);
margin-inline: auto;
.preview {
display: flex;
gap: 1em;
align-items: center;
margin-block-end: 1em;
}
.presets {
display: flex;
gap: 0.6em;
justify-content: center;
margin-block-start: 1.5em;
}
.swatch {
inline-size: 3em;
block-size: 2em;
background:
linear-gradient(var(--color), var(--color)),
repeating-conic-gradient(#ccc 0 25%, #fff 0 50%) 0 0 / 0.5em 0.5em;
border: 1px solid var(--sv-gray-5);
border-radius: var(--sv-bdr-rad-md);
}
output {
font-family: monospace;
}
.areas {
display: grid;
grid-template-columns: repeat(auto-fit, min(100%, 11.5em));
gap: 1.5em 1em;
align-items: end;
justify-content: center;
}
.field {
display: grid;
gap: 0.5em;
}
label {
font-size: 0.9em;
font-weight: 600;
}
sv-color-area {
--sv-area-slider-width: 100%;
}
}
</style>

Wheels and Rings

Edit the HSV and RGB channels of one color with a color wheel inside a ring. ring turns an sv-color-wheel into a ring with one channel, channels picks the angle and radius channels of the wheel inside it, and color-space="rgb" enables the RGB channels.

HSV
RGB
<div class="color-group-wheels">
<sv-color-group value="#3b82f6">
<div class="preview">
<div class="swatch"></div>
<output></output>
</div>
<div class="pickers">
<div class="field">
<span class="label">HSV</span>
<div class="picker">
<sv-color-wheel
adaptive
aria-label="Brightness"
channels="brightness"
ring
></sv-color-wheel>
<sv-color-wheel
adaptive
aria-label="Hue and saturation"
channels="hue saturation"
></sv-color-wheel>
</div>
</div>
<div class="field">
<span class="label">RGB</span>
<div class="picker">
<sv-color-wheel
adaptive
aria-label="Blue"
channels="blue"
color-space="rgb"
ring
></sv-color-wheel>
<sv-color-wheel
adaptive
aria-label="Red and green"
channels="red green"
color-space="rgb"
></sv-color-wheel>
</div>
</div>
</div>
<div class="presets" aria-label="Presets" role="radiogroup">
<sv-color-swatch
aria-label="Blue"
name="color-group-wheels-preset"
value="#3b82f6"
></sv-color-swatch>
<sv-color-swatch
aria-label="Teal"
name="color-group-wheels-preset"
value="#0d9488"
></sv-color-swatch>
<sv-color-swatch
aria-label="Amber"
name="color-group-wheels-preset"
value="#d97706"
></sv-color-swatch>
<sv-color-swatch
aria-label="Rose"
name="color-group-wheels-preset"
value="#e11d48"
></sv-color-swatch>
</div>
</sv-color-group>
</div>
<script type="application/x-typescript" module>
const wrapper = document.querySelector<HTMLDivElement>(".color-group-wheels")!;
const colorGroup = wrapper.querySelector<ColorGroup>("sv-color-group")!;
const valueOutput = wrapper.querySelector<HTMLOutputElement>("output")!;
updateValueOutput();
colorGroup.addEventListener("valuechange", updateValueOutput);
function updateValueOutput() {
valueOutput.value = colorGroup.value;
wrapper.style.setProperty("--color", colorGroup.value);
}
</script>
<style>
.color-group-wheels {
--color: #3b82f6;
.preview {
display: flex;
gap: 1em;
align-items: center;
justify-content: center;
margin-block-end: 1.5em;
}
.presets {
display: flex;
gap: 0.6em;
justify-content: center;
margin-block-start: 1.5em;
}
.swatch {
inline-size: 3em;
block-size: 2em;
background:
linear-gradient(var(--color), var(--color)),
repeating-conic-gradient(#ccc 0 25%, #fff 0 50%) 0 0 / 0.5em 0.5em;
border: 1px solid var(--sv-gray-5);
border-radius: var(--sv-bdr-rad-md);
}
output {
font-family: monospace;
}
.pickers {
display: flex;
flex-wrap: wrap;
gap: 2em;
justify-content: center;
}
.field {
display: grid;
gap: 0.75em;
justify-items: center;
}
.label {
font-size: 0.9em;
font-weight: 600;
}
.picker {
display: grid;
place-items: center;
> * {
grid-area: 1 / 1;
}
}
sv-color-wheel[ring] {
--sv-polar-slider-sz: 14em;
--sv-polar-slider-track-thickness: 1.25em;
}
sv-color-wheel:not([ring]) {
--sv-polar-slider-sz: 10.5em;
}
}
</style>