StealThis .dev

Toggle Group

Group of toggle buttons for single or multi-selection — like a toolbar or filter chip group. Keyboard navigation with arrow keys.

Open in Lab
css vanilla-js
Targets: JS HTML

Code

Toggle Group

A flexible group of toggle buttons that supports both single-select (like a radio group) and multi-select (like checkboxes) modes. Matches the WAI-ARIA toolbar pattern and supports full keyboard navigation with arrow keys.

How it works

  1. Each .toggle-group has a data-mode attribute: "single" or "multi"
  2. In single mode, selecting a button deselects all others (radio-like)
  3. In multi mode, each button toggles independently (checkbox-like)
  4. aria-pressed reflects the active state for screen readers
  5. Arrow keys navigate within the group; Home/End jump to first/last

Demos

Single-select — Text Formatting toolbar: Bold, Italic, Underline, Strikethrough — only one active at a time

Multi-select — Filter chips: Design, Development, Motion, 3D, Branding — multiple selections allowed

Keyboard navigation

KeyAction
/ Next button
/ Previous button
HomeFirst button
EndLast button
Space / EnterActivate focused button

When to use it

  • Text editor toolbars (bold/italic/underline)
  • View mode switchers (grid/list/kanban)
  • Filter chip groups
  • Segmented controls