Components / Forms
Toggle Group
Groups a set of toggle buttons.
<div class="toggle-group" role="group" aria-label="Text formatting">
<button type="button" class="toggle" aria-pressed="true">Bold</button>
<button type="button" class="toggle" aria-pressed="false">Italic</button>
<button type="button" class="toggle" aria-pressed="false">Underline</button>
</div>Installation
pnpm dlx loseta add toggle-groupnpx loseta add toggle-groupExamples
Outline
<div class="toggle-group" role="group" aria-label="Text styles" data-variant="outline">
<button type="button" class="toggle" aria-pressed="true" aria-label="Toggle bold"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"/></svg></button>
<button type="button" class="toggle" aria-pressed="false" aria-label="Toggle italic"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="19" x2="10" y1="4" y2="4"/><line x1="14" x2="5" y1="20" y2="20"/><line x1="15" x2="9" y1="4" y2="20"/></svg></button>
<button type="button" class="toggle" aria-pressed="false" aria-label="Toggle underline"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" x2="20" y1="20" y2="20"/></svg></button>
</div>Sizes
<div style="display: grid; gap: 0.75rem; justify-items: start">
<div class="toggle-group" role="group" aria-label="Small alignment" data-variant="outline" data-size="sm">
<button type="button" class="toggle" aria-pressed="true">Top</button>
<button type="button" class="toggle" aria-pressed="false">Bottom</button>
</div>
<div class="toggle-group" role="group" aria-label="Default alignment" data-variant="outline">
<button type="button" class="toggle" aria-pressed="true">Top</button>
<button type="button" class="toggle" aria-pressed="false">Bottom</button>
</div>
<div class="toggle-group" role="group" aria-label="Large alignment" data-variant="outline" data-size="lg">
<button type="button" class="toggle" aria-pressed="true">Top</button>
<button type="button" class="toggle" aria-pressed="false">Bottom</button>
</div>
</div>Spacing
<div style="display: grid; gap: 0.75rem; justify-items: start">
<div class="toggle-group" role="group" aria-label="Default spacing" data-variant="outline" data-spacing="default">
<button type="button" class="toggle" aria-pressed="true">Bold</button>
<button type="button" class="toggle" aria-pressed="false">Italic</button>
<button type="button" class="toggle" aria-pressed="false">Underline</button>
</div>
<div class="toggle-group" role="group" aria-label="Joined spacing" data-variant="outline" data-spacing="joined">
<button type="button" class="toggle" aria-pressed="true">Bold</button>
<button type="button" class="toggle" aria-pressed="false">Italic</button>
<button type="button" class="toggle" aria-pressed="false">Underline</button>
</div>
</div>Vertical
<div style="display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1rem">
<div class="toggle-group" role="group" aria-label="Text formatting vertical" data-variant="outline" data-orientation="vertical">
<button type="button" class="toggle" aria-pressed="true" aria-label="Toggle bold"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"/></svg></button>
<button type="button" class="toggle" aria-pressed="true" aria-label="Toggle italic"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="19" x2="10" y1="4" y2="4"/><line x1="14" x2="5" y1="20" y2="20"/><line x1="15" x2="9" y1="4" y2="20"/></svg></button>
<button type="button" class="toggle" aria-pressed="false" aria-label="Toggle underline"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" x2="20" y1="20" y2="20"/></svg></button>
</div>
<div class="toggle-group" role="group" aria-label="View density" data-orientation="vertical" data-spacing="joined" data-variant="outline" data-size="sm">
<button type="button" class="toggle" aria-pressed="true">Compact</button>
<button type="button" class="toggle" aria-pressed="false">Default</button>
<button type="button" class="toggle" aria-pressed="false">Comfortable</button>
</div>
</div>Disabled
<div class="toggle-group" role="group" aria-label="Disabled formatting" data-variant="outline">
<button type="button" class="toggle" aria-pressed="false" disabled>Bold</button>
<button type="button" class="toggle" aria-pressed="true" disabled>Italic</button>
<button type="button" class="toggle" aria-pressed="false" disabled>Underline</button>
</div>Right-to-left
<div dir="rtl" lang="ar">
<div class="toggle-group" role="group" aria-label="عرض المحتوى" data-variant="outline">
<button type="button" class="toggle" aria-pressed="true" aria-label="قائمة"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 5h.01"/><path d="M3 12h.01"/><path d="M3 19h.01"/><path d="M8 5h13"/><path d="M8 12h13"/><path d="M8 19h13"/></svg></button>
<button type="button" class="toggle" aria-pressed="false" aria-label="شبكة"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M3 9h18"/><path d="M3 15h18"/><path d="M9 3v18"/><path d="M15 3v18"/></svg></button>
<button type="button" class="toggle" aria-pressed="false" aria-label="بطاقات"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg></button>
</div>
</div>Accessibility and behavior
- Wrap toggles in role="group" with an accessible label. Each toggle carries its own aria-pressed. Single-choice selection belongs to a radio group. Group data-variant and data-size apply to children without their own attribute; data-spacing="joined" collapses the shared borders and rounds only the outer corners.
Files
components/toggle-group.cssbasestyles/nova/toggle-group.cssstyleInstall contract
The CLI writes the base file under components/, the visual file for the selected style under styles/<name>/, and any primitive dependency underprimitives/. The generated index.css imports them in the right layer order.