---
title: "Button Group"
description: "Button Group component - group related buttons with shared borders and spacing."
slug: "button-group"
---

import { DocPage, PageHeader, SkillPanel, SourceFiles, SourceNote, StatesSection, CodeBlock, Demo, DemoCode, ChangelogEntries, ArchBody, StatsClaim, StatsCards, PageOverlay, DocText, DocLink, H2, SkillField, SkillText, SkillRow, SkillGrid, Variant, ApiPill, Dim, CodeCard, TableCard } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="button-group" title="Button Group" component="button-group">
  Groups related buttons with connected borders. Built on a <code>&lt;div&gt;</code> container that merges adjacent button edges. CSS only - no JavaScript.
</PageHeader>

<SkillPanel component="button-group">
  <SkillField label="Native basis">
<SkillText><code>&lt;div&gt;</code> container with <code>.btn</code> buttons. Visually merges adjacent buttons with connected borders.</SkillText>
  </SkillField>

  <SkillField label="Web Platform APIs">
<SkillRow>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/group_role" title="groups related buttons"><code>role="group"</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label" title="accessible name for the group"><code>aria-label</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/separator_role" title="visually divides buttons within a group"><code>role="separator"</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/:has" title="restores radius on buttons adjacent to separators"><code>:has()</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values" title="RTL support via logical properties"><code>Logical properties</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors" title="maps separator to system ButtonText"><code>forced-colors</code></ApiPill>
  </SkillRow>
  </SkillField>

  <SkillField label="Classes">
<SkillRow>
    <code>.btn-group</code>
    <code>.btn</code>
  </SkillRow>
  </SkillField>

  <SkillField label="Data attributes">
<SkillText>• <code>data-orientation</code> - values: <code>vertical</code></SkillText>
  </SkillField>

  <SkillField label="Notes">
<SkillText dense>• Button groups work best with the <code>outline</code> variant - the connected borders create a cohesive unit.</SkillText>
  <SkillText dense>• Adjacent button borders collapse so only one border renders between buttons.</SkillText>
  <SkillText dense>• The group removes internal border-radii to create seamless joins.</SkillText>
  <SkillText dense>• Use <code>&lt;hr role="separator"&gt;</code> in Split buttons to divide the primary action from its dropdown trigger - it is the single 1px line between them (the neighbouring borders drop, the inner corners stay square), and the trigger opens a Dropdown menu placed after the group.</SkillText>
  <SkillText dense>• Uses CSS logical properties for automatic RTL support.</SkillText>
  <p class="text-muted-foreground m-0">• No JavaScript required - this is purely a CSS layout component.</p>
  </SkillField>
</SkillPanel>

```html example label="Horizontal" hint="Default horizontal group with connected outline buttons."
<div class="btn-group" role="group" aria-label="Actions">
  <button class="btn" data-variant="outline">Save</button>
  <button class="btn" data-variant="outline">Edit</button>
  <button class="btn" data-variant="outline">Delete</button>
</div>
```

```html example label="With icons" hint="Icon-only button group for compact toolbars."
<div class="btn-group" role="group" aria-label="Formatting">
  <button class="btn" data-variant="outline" data-size="icon" aria-label="Bold">
    <i data-lucide="bold"></i>
  </button>
  <button class="btn" data-variant="outline" data-size="icon" aria-label="Italic">
    <i data-lucide="italic"></i>
  </button>
  <button class="btn" data-variant="outline" data-size="icon" aria-label="Underline">
    <i data-lucide="underline"></i>
  </button>
</div>
```

```html example label="Vertical" hint="Stacked buttons with connected top/bottom borders."
<div class="btn-group" data-orientation="vertical" role="group" aria-label="Nav">
  <button class="btn" data-variant="outline">Top</button>
  <button class="btn" data-variant="outline">Middle</button>
  <button class="btn" data-variant="outline">Bottom</button>
</div>
```

```html example label="Sizes" hint="Button size is controlled with data-size on the individual .btn children - group them at any step of the full scale."
<div style="display: flex; flex-direction: column; gap: 1rem; align-items: center">
  <div class="btn-group" role="group" aria-label="Extra small actions">
    <button class="btn" data-variant="outline" data-size="xs">Save</button>
    <button class="btn" data-variant="outline" data-size="xs">Edit</button>
  </div>
  <div class="btn-group" role="group" aria-label="Small actions">
    <button class="btn" data-variant="outline" data-size="sm">Save</button>
    <button class="btn" data-variant="outline" data-size="sm">Edit</button>
    <button class="btn" data-variant="outline" data-size="icon-sm" aria-label="More">
      <i data-lucide="ellipsis"></i>
    </button>
  </div>
  <div class="btn-group" role="group" aria-label="Medium actions">
    <button class="btn" data-variant="outline" data-size="md">Save</button>
    <button class="btn" data-variant="outline" data-size="md">Edit</button>
    <button class="btn" data-variant="outline" data-size="icon" aria-label="More">
      <i data-lucide="ellipsis"></i>
    </button>
  </div>
  <div class="btn-group" role="group" aria-label="Large actions">
    <button class="btn" data-variant="outline" data-size="lg">Save</button>
    <button class="btn" data-variant="outline" data-size="lg">Edit</button>
    <button class="btn" data-variant="outline" data-size="icon-lg" aria-label="More">
      <i data-lucide="ellipsis"></i>
    </button>
  </div>
  <div class="btn-group" role="group" aria-label="Extra large actions">
    <button class="btn" data-variant="outline" data-size="xl">Save</button>
    <button class="btn" data-variant="outline" data-size="xl">Edit</button>
  </div>
</div>
```

```html example label="Split button" hint="The main action plus a menu of related ones. The separator is the single 1px line between them - the two halves stay one control. The chevron is a Dropdown trigger (data-dropdown-trigger + aria-haspopup=&quot;menu&quot;); the menu sits after the group and lines up with the chevron's end (data-align=&quot;end&quot;). Arrow keys move through the menu, Escape closes it and returns focus to the chevron." height="18"
<div class="btn-group" role="group" aria-label="Split action">
  <button class="btn" data-variant="outline" id="split-save">Save</button>
  <hr role="separator" />
  <button
    class="btn"
    data-variant="outline"
    data-size="icon"
    aria-label="More save options"
    aria-haspopup="menu"
    aria-expanded="false"
    aria-controls="split-menu"
    data-dropdown-trigger="split-menu"
  >
    <svg
      aria-hidden="true"
      width="16"
      height="16"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
    >
      <path d="m6 9 6 6 6-6" />
    </svg>
  </button>
</div>
<div id="split-menu" role="menu" popover class="dropdown-content" data-align="end" aria-label="Save options">
  <button role="menuitem" class="dropdown-item" tabindex="-1">Save as draft</button>
  <button role="menuitem" class="dropdown-item" tabindex="-1">Save a copy</button>
  <button role="menuitem" class="dropdown-item" tabindex="-1">Save and close</button>
  <div class="dropdown-separator" role="separator"></div>
  <button role="menuitem" class="dropdown-item" tabindex="-1">Schedule…</button>
</div>
<p class="text-sm text-muted-foreground" style="margin: 0.75rem 0 0"
  >Last action: <output id="split-out">none</output></p
>
<script>
  const out = document.getElementById('split-out');
  document.getElementById('split-save').addEventListener('click', () => {
    out.textContent = 'Save';
  });
  document.getElementById('split-menu').addEventListener('click', (e) => {
    const item = e.target.closest('[role="menuitem"]');
    if (item) out.textContent = item.textContent.trim();
  });
</script>
```

<SourceFiles component="button-group" section="css" />

</DocPage>
