Skip to content
English

How it works

A recessed track holds the toggles. In single mode one raised thumb is measured under the pressed toggle and glides to the next with a soft spring while the labels only change colour, so nothing reflows. In multiple mode each pressed toggle rises on its own and pressed neighbours drop their inner corners, fusing into one continuous chip that reads as one active span.

Use it for

  • Text formatting such as bold, italic and underline (multiple).
  • Switching a view mode or alignment among two to five options (single).

Look elsewhere when

  • Switching between page sections: use tabs.
  • Options in a form that is submitted later: use radio buttons or checkboxes.

Usage

import { useState } from 'react'
import { ToggleGroup } from './ToggleGroup.jsx'

export function FormatBar() {
  const [marks, setMarks] = useState(['bold'])
  const [view, setView] = useState('edit')
  return (
    <>
      <ToggleGroup
        label="View mode"
        value={view}
        onValueChange={setView}
        items={[
          { value: 'edit', label: 'Edit' },
          { value: 'preview', label: 'Preview' },
        ]}
      />
      <ToggleGroup
        type="multiple"
        iconOnly
        label="Text formatting"
        value={marks}
        onValueChange={setMarks}
        items={[
          { value: 'bold', label: 'Bold', icon: <BoldIcon /> },
          { value: 'italic', label: 'Italic', icon: <ItalicIcon /> },
        ]}
      />
    </>
  )
}

Props

PropTypeDefaultWhat it does
itemsArray<{ value: string, label: string, icon?: ReactNode, disabled?: boolean }>—The toggles. With iconOnly the label becomes the accessible name and tooltip.
type'single' | 'multiple''single'One pressed at a time, or any number.
valuestring | null | string[]—Controlled value: a string for single, an array for multiple.
defaultValuestring | string[]—Initial value when uncontrolled.
onValueChange(value) => void—Called with the new value.
allowEmptybooleanfalseSingle mode: pressing the pressed toggle again clears the choice.
iconOnlybooleanfalseSquare toggles showing only the icon.
size'sm' | 'md' | 'lg''md'Toggle height 32, 36 or 44px.
labelstring—Accessible name of the group.
disabledbooleanfalseDisables every toggle.

Accessibility

  • The container is role="group" with an accessible name from label; every toggle is a native button with aria-pressed.
  • One toggle is in the tab order (roving tabindex); arrow keys move focus and wrap, Home and End jump, disabled toggles are skipped, and left/right follow the reading direction.
  • Space or Enter presses the focused toggle; icon-only toggles get their label as aria-label and title.
  • Pressed state is shown by a raised surface and darker text, not by colour alone; toggles are 32px or taller.
  • Reduced motion stops the thumb gliding and the press scale; only colours change.

Motion

The single-mode thumb glides in 360ms with a soft spring (slight overshoot). Pressing scales a toggle to 96% for 100ms; corners and surfaces change in 160ms.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

ToggleGroup.jsxtoggle-group.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Buttons
Aurora rim button comes with Pro. Its preview shows once you unlock it.
Bite button comes with Pro. Its preview shows once you unlock it.