Skip to content

Toggle Group Examples

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

Basic

Group toggle buttons and let several be pressed at once. Give each sv-toggle a value, and the group's space-separated value sets which start pressed.

Bold Italic Underline
Selection
State
Focus
<div class="group-basic">
<sv-toggle-group aria-label="Text formatting" value="bold italic">
<sv-toggle value="bold">Bold</sv-toggle>
<sv-toggle value="italic">Italic</sv-toggle>
<sv-toggle value="underline">Underline</sv-toggle>
</sv-toggle-group>
</div>
<style>
.group-basic {
display: flex;
align-items: center;
justify-content: center;
sv-toggle-group {
gap: 0.5rem;
}
}
</style>

Toolbar

Mark a group as a bar of controls for assistive technology. role="toolbar" makes it a toolbar, and aria-orientation="vertical" marks stacked buttons.

Bold Italic Code role="toolbar"
Pen Brush Eraser aria-orientation="vertical"
<div class="group-toolbar">
<div class="variant">
<sv-toggle-group aria-label="Text formatting" role="toolbar" value="bold">
<sv-toggle value="bold">Bold</sv-toggle>
<sv-toggle value="italic">Italic</sv-toggle>
<span class="divider" aria-hidden="true"></span>
<sv-toggle value="code">Code</sv-toggle>
</sv-toggle-group>
<span>role="toolbar"</span>
</div>
<div class="variant">
<sv-toggle-group
class="vertical"
aria-label="Drawing tools"
aria-orientation="vertical"
exclusive
role="toolbar"
value="pen"
>
<sv-toggle value="pen">Pen</sv-toggle>
<sv-toggle value="brush">Brush</sv-toggle>
<sv-toggle value="eraser">Eraser</sv-toggle>
</sv-toggle-group>
<span>aria-orientation="vertical"</span>
</div>
</div>
<style>
.group-toolbar {
display: grid;
gap: 1.5em;
justify-items: center;
.variant {
display: grid;
gap: 0.4em;
justify-items: center;
> span {
font-size: 0.8em;
color: var(--sv-gray-3);
}
}
sv-toggle-group {
gap: 0.5rem;
}
.divider {
inline-size: var(--sv-bdr-sz-sm);
block-size: 1.2em;
background-color: var(--sv-gray-5);
}
.vertical {
flex-direction: column;
align-items: stretch;
}
}
</style>