Skip to content

Chip Examples

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

Basic

Add a selectable pill with a label, for a filter or a tag. The default slot holds the label, and a click or Space toggles checked.

The controls show the variants, the states, and the styling.

In the filled variant, setting --sv-accent-content to contrast-color() of the accent keeps the label and the check icon readable on any accent color.

Awesome chip
Look
Keeps the space of the check icon. The chip then keeps its width.
State
Style
1rem
Sets font-size , which scales the whole chip.
accent color
Sets --sv-accent , which every variant reads.
2em
Sets --sv-chip-bdr-rad .
<div class="chip-basic">
<sv-chip>Awesome chip</sv-chip>
</div>
<style>
.chip-basic {
display: flex;
align-items: center;
justify-content: center;
sv-chip {
@supports (color: contrast-color(red)) {
--sv-accent-content: contrast-color(var(--sv-accent));
}
}
}
</style>

Multiple Selection

Let the user pick several options, and send them all with a form. Checkbox chips with the same name each submit their value, and the checkedchange event updates the summary.

Topics News Sport Music Travel
news
<form class="chip-multiple-selection">
<fieldset>
<legend>Topics</legend>
<sv-chip checked name="topics" value="news">News</sv-chip>
<sv-chip name="topics" value="sport">Sport</sv-chip>
<sv-chip name="topics" value="music">Music</sv-chip>
<sv-chip name="topics" value="travel">Travel</sv-chip>
</fieldset>
<output>news</output>
</form>
<script type="application/x-typescript" module>
const form = document.querySelector<HTMLFormElement>(".chip-multiple-selection")!;
const output = form.querySelector("output")!;
for (const chip of form.querySelectorAll<Chip>("sv-chip")) {
chip.addEventListener("checkedchange", () => {
const selectedTopics = new FormData(form).getAll("topics");
output.textContent = selectedTopics.join(", ") || "Nothing selected";
});
}
</script>
<style>
.chip-multiple-selection {
display: grid;
gap: 1em;
justify-items: center;
fieldset {
display: flex;
flex-wrap: wrap;
gap: 0.5em;
justify-content: center;
padding: 0;
margin: 0;
border: none;
}
legend {
padding-block-end: 0.5em;
margin-inline: auto;
}
output {
font-size: 0.85em;
color: var(--sv-gray-3);
}
}
</style>

Radio Group

Let the user pick one option from a short list. type="radio" with the same name makes one group, and a <fieldset role="radiogroup"> with a <legend> names it.

Focus a chip and press the arrow keys to move through the group.

Size Small Medium Large
<fieldset class="chip-radio-group" role="radiogroup">
<legend>Size</legend>
<sv-chip type="radio" name="chip-size" value="small">Small</sv-chip>
<sv-chip type="radio" checked name="chip-size" value="medium">Medium</sv-chip>
<sv-chip type="radio" name="chip-size" value="large">Large</sv-chip>
</fieldset>
<style>
.chip-radio-group {
display: flex;
flex-wrap: wrap;
gap: 0.5em;
justify-content: center;
padding: 0;
margin: 0;
border: none;
legend {
padding-block-end: 0.5em;
margin-inline: auto;
}
}
</style>

Deselect Radio

Let the user clear a single-choice selection with a second click on the checked chip. deselectable on a type="radio" chip lets a click or Space uncheck it.

Framework React Vue Svelte
<fieldset class="chip-deselect-radio" role="radiogroup">
<legend>Framework</legend>
<sv-chip type="radio" checked deselectable name="chip-framework" value="react">React</sv-chip>
<sv-chip type="radio" deselectable name="chip-framework" value="vue">Vue</sv-chip>
<sv-chip type="radio" deselectable name="chip-framework" value="svelte">Svelte</sv-chip>
</fieldset>
<style>
.chip-deselect-radio {
display: flex;
flex-wrap: wrap;
gap: 0.5em;
justify-content: center;
padding: 0;
margin: 0;
border: none;
legend {
padding-block-end: 0.5em;
margin-inline: auto;
}
}
</style>

Slots

Add an icon or other content beside the chip label. The before slot holds the star before the label, and it stays visible in every state.

The controls move the check icon, keep its space, add content after the label, and replace the check icon.

Favorites
Inserts a count in the after slot.
Inserts an icon in the checked-icon slot.
<div class="chip-slots">
<sv-chip checked>
<!-- Star -->
<svg
aria-hidden="true"
slot="before"
viewBox="0 -960 960 960"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="m233-120 65-281L80-590l288-25 112-265 112 265 288 25-218 189 65 281-247-149-247 149Z"
></path>
</svg>
Favorites
</sv-chip>
</div>
<style>
.chip-slots {
display: flex;
align-items: center;
justify-content: center;
svg {
inline-size: 1em;
block-size: 1em;
fill: currentcolor;
}
}
</style>