Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Button Group for Ark UI

A button group for React on Ark UI that joins buttons, menus, selects and inputs into one bar with shared borders, in a row or a column.

On this page9 sections

A button group joins related controls into one bar. The borders between them merge and the inner corners go square, so Archive, Report and Snooze read as a single toolbar while each stays a separate button with its own action and its own tab stop.

Nothing in the group stays selected. When one option should stay pressed, as in a view switcher, use a Toggle Group. For icons and addons inside a text field's own border, use an Input Group.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Button Group anatomy: root, group, button, separator

Usage

import { Button } from "@/components/ui/button";
import { ButtonGroup } from "@/components/ui/button-group";
<ButtonGroup aria-label="Message actions">
  <Button variant="outline">Archive</Button>
  <Button variant="outline">Report</Button>
  <Button variant="outline">Snooze</Button>
</ButtonGroup>

Accessibility

ButtonGroup renders a div with role="group" and handles no keys of its own. A screen reader announces a group by its name, and it has none until you give it one with aria-label or aria-labelledby, so name a group whose buttons only make sense together. That name doesn't reach the buttons inside: each icon-only button still needs its own aria-label. Every control keeps its own tab stop, and a menu or select in the group brings its own keys once it opens.

Tab
Moves focus to the next control in the group, and past the last one out of it.
Shift+Tab
Moves focus to the previous control.

Demos

Orientation

Zoom in and Zoom out, a plus and a minus, stacked in a column with orientation set to vertical on a group named Zoom. The shared border now runs between top and bottom, and only the outer corners stay round. Each icon button has its own aria-label, since the group's name doesn't reach them. Use a column for a pair docked to the edge of a map or canvas.

Preview width

Size

Three groups, each with three outline buttons and a plus, at sm, the default md and lg, the plus at icon-sm, icon-md or icon-lg to match. The group has no size of its own, so set size on every button in it. Mixed heights turn the shared border into steps.

Preview width

Nested

An outer group holding two inner ones: a plus button, then a message field whose voice icon shows a tooltip. Groups nested like this sit a small gap apart instead of sharing a border, which suits a composer or a toolbar of separate clusters. Keep everything in one group when every control should share the same edge.

Preview width

Separator

Copy and Paste as small secondary buttons with ButtonGroupSeparator between them. Secondary buttons have no visible border to share, so without the separator the two would blur into one filled block. Reach for it whenever the buttons in a group are filled rather than outlined.

Preview width

Split

A secondary button and a plus icon button with a separator between them, the classic split button. The labeled side is the main action and the icon is a related one beside it, so both are a press away without a menu. Use it when the second action is common enough to deserve its own hit area.

Preview width

Input

A search field and a search icon button in one group. The group gives a direct input child flex-1, so once you widen the group, with w-full for instance, the field takes the extra width and the button keeps its own. The field is named Search with aria-label, since a placeholder isn't a label. Use it for a search or submit that belongs to one field.

Preview width

Text

A website field with https:// in a ButtonGroupText before it and a Save button after it. The text part joins the group's shared border like a button does, so the prefix reads as part of the field without being typed into it. The field has its own aria-label, since the prefix beside it doesn't name it.

Preview width

Input group

A rounded composer: a plus button in its own group, then a message field from Input Group with a voice button at its end. Pressing voice sets aria-pressed, tints the button, disables the text field and swaps the placeholder for a recording prompt. Setting --radius to 9999rem on the outer group turns every corner into a pill.

Preview width

Follow is the main button, and the chevron beside it opens a menu of six conversation actions with a destructive Delete at the bottom. The chevron is the menu's trigger and still a Button, so it takes the group's shared border. Use this split when one action is common and the rest are occasional.

Preview width

Select

A currency Select and an amount field in an inner group, with a send button in a second group beside them. The trigger shows the symbol, dollars to start, and the list adds euro and pound. Nest it this way when the submit should sit a little apart from the fields it sends.

Preview width

Popover

Copilot is the labeled button, and the chevron beside it opens a Popover aligned to its end edge, with a task field and a note that Copilot will open a pull request. Choose a popover over a menu when the second action needs a little input before it runs.

Preview width

RTL

The opening toolbar with Arabic labels, inside a container whose dir is rtl: back, archive and report, snooze, and the more menu with its label submenu. The corner and border classes are logical, so the groups join along the reading direction, and the back arrow carries rtl:rotate-180. Use it to check a toolbar in Arabic or Hebrew.

Preview width

FAQ

How do I stack a Button Group vertically in React?

Set orientation to vertical on ButtonGroup, as the Orientation demo does. The buttons stack in a column, the borders join between top and bottom, and the root's data-orientation changes to match, so your own styles can follow it. Leave the prop out for the default, horizontal.

A vertical group is as wide as its widest button, and it stretches the text buttons to that width so their edges line up. Icon buttons keep their square size.

How do I add a divider between buttons in a Button Group?

Put ButtonGroupSeparator between the two buttons, as the Separator demo does. It defaults to vertical, the right line for a row, so set its orientation to horizontal inside a vertical group.

A separator matters most with filled buttons, such as secondary, which have no visible border to divide them. For a gap between clusters rather than a line, nest one group inside another, as the Nested demo does.

Does a Button Group move focus with the arrow keys?

No. ButtonGroup is a div with role="group" and no key handling, so each button is its own tab stop: Tab and Shift+Tab move through them in order, and Enter or Space presses the focused one. A menu or select inside the group brings its own keys once it opens.

In a long row of icon buttons that costs keyboard users one Tab press each. When the row is a single choice, such as alignment or view mode, a Toggle Group is the better fit.

How do I put an input or a select in a Button Group?

Place the Input or the Select in the group next to the buttons, as the Input and Select demos do. An Input placed directly in the group gets flex-1, so when the group is wider than its contents, the field takes the extra width and the buttons keep their own.

To keep a submit button slightly apart from the fields it sends, put the fields in one inner group and the button in another, as the Select demo does. ButtonGroupText holds static text inside the bar, such as a currency symbol or a https:// prefix, as the Text demo shows.

When should I use a Button Group instead of a Toggle Group?

Use a Button Group when each button runs its own action and nothing stays pressed afterward: Archive and Snooze, Copy and Paste, zoom in and zoom out. The group tracks no value and no pressed state.

Use a Toggle Group when the buttons are options and one or several stay on, as with bold and italic in an editor or a list and grid view switch. It keeps the selected value for you and tells screen readers which options are on.

Why does a wrapped button break the joined corners in a Button Group?

The group squares and joins only its direct children that carry a data-slot attribute, which every component in this kit sets on its root. A plain div or span around a button is skipped, so the button inside keeps all four rounded corners and its full border, and the seam shows. Make the button itself the direct child: let a trigger render onto it rather than wrap it, as the Dropdown demo does with the menu trigger.

How do I make a Button Group fill the full width?

The group is w-fit by default, so it shrinks to its buttons. Add w-full to the group's classes and flex-1 to each button, and the buttons share the width between them while the borders stay joined.

An input placed directly in the group already takes flex-1, so in a search bar only the group needs w-full, and the field grows while the buttons keep their size.

API Reference

ButtonGroup

<div> data-slot="button-group"

PropType
orientation?"horizontal" | "vertical"

Lays the buttons out in a row (horizontal) or a column (vertical), their touching corners squared and borders shared. A Select's trigger sits inside the select's own root and control, so it is joined by classes of its own.

Type
"horizontal" | "vertical"
Default
"horizontal"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

className?string

Merged with the part's classes.

AttributeType
data-orientation?string

Mirrors orientation.

ButtonGroupText

<div> data-slot="button-group-text"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

className?string

Merged with the part's classes.

ButtonGroupSeparator

data-slot="button-group-separator"

PropType
orientation?"horizontal" | "vertical"

The orientation of the separator. Ark default: horizontal.

Type
"horizontal" | "vertical"
Default
"vertical"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

className?string

Merged with the part's classes.