Toggle Group

A set of related choices styled as toggle buttons.

Text formatting

Usage

Use a Basecoat style bundle. No JavaScript is required. See Installation.

<fieldset>
  <legend class="sr-only">Text formatting</legend>
  <div class="flex gap-2">
    <label class="btn" data-variant="outline" data-size="icon">
      <input type="checkbox" name="toggle-group-2" value="bold" aria-label="Bold" />
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" 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 8H6V4h8a4 4 0 0 1 0 8" /></svg>
    </label>
    <label class="btn" data-variant="outline" data-size="icon">
      <input type="checkbox" name="toggle-group-2" value="italic" aria-label="Italic" />
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 4h-9M14 20H5M15 4 9 20" /></svg>
    </label>
    <label class="btn" data-variant="outline" data-size="icon">
      <input type="checkbox" name="toggle-group-2" value="underline" aria-label="Underline" />
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" 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 0V4M4 20h16" /></svg>
    </label>
  </div>
</fieldset>

Use checkboxes for independent choices or radios with the same name for a single choice. Give each radio group a unique name. Set checked for an initial selection and disabled on an input or the whole fieldset.

Unlike upstream’s pressed buttons, these expose checkbox/radio semantics. A selected radio cannot be cleared by clicking it again. Native radio arrow-key navigation and checkbox Tab/Space behavior apply.

HTML structure

Group the inputs in a fieldset with a legend. Use flex gap-2 for separated controls, or wrap .btn labels in .button-group for joined controls. Set Button variants and sizes on each label. Inputs support native form submission, reset, and change events.

Examples

Outline

Call filter

Size

Position
Position

Spacing

Use gap-2 for an 8px gap. To join the same controls, replace flex gap-2 with button-group.

Position

Vertical

Use flex flex-col gap-1 for separated vertical controls. For joined controls, use .button-group with data-orientation="vertical".

Text formatting

Disabled

Disable the entire group with <fieldset disabled>.

Text formatting

Custom

Font Weight

RTL

طريقة العرض