apps/v4/content/docs/components/base/button-group.mdx
npx shadcn@latest add button-group
<Step>Install the following dependencies:</Step>
npm install @base-ui/react
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource name="button-group" title="components/ui/button-group.tsx" styleName="base-nova" />
<Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsContent> </CodeTabs>import {
ButtonGroup,
ButtonGroupSeparator,
ButtonGroupText,
} from "@/components/ui/button-group"
<ButtonGroup>
<Button>Button 1</Button>
<Button>Button 2</Button>
</ButtonGroup>
ButtonGroup component has the role attribute set to group.aria-label or aria-labelledby to label the button group.<ButtonGroup aria-label="Button group">
<Button>Button 1</Button>
<Button>Button 2</Button>
</ButtonGroup>
ButtonGroup component when you want to group buttons that perform an action.ToggleGroup component when you want to group buttons that toggle a state.Set the orientation prop to change the button group layout.
Control the size of buttons using the size prop on individual buttons.
Nest <ButtonGroup> components to create button groups with spacing.
The ButtonGroupSeparator component visually divides buttons within a group.
Buttons with variant outline do not need a separator since they have a border. For other variants, a separator is recommended to improve the visual hierarchy.
Create a split button group by adding two buttons separated by a ButtonGroupSeparator.
Wrap an Input component with buttons.
Wrap an InputGroup component to create complex input layouts.
Create a split button group with a DropdownMenu component.
Pair with a Select component.
Use with a Popover component.
To enable RTL support in shadcn/ui, see the RTL configuration guide.
<ComponentPreview styleName="base-nova" name="button-group-rtl" direction="rtl" />
The ButtonGroup component is a container that groups related buttons together with consistent styling.
| Prop | Type | Default |
|---|---|---|
orientation | "horizontal" | "vertical" | "horizontal" |
<ButtonGroup>
<Button>Button 1</Button>
<Button>Button 2</Button>
</ButtonGroup>
Nest multiple button groups to create complex layouts with spacing. See the nested example for more details.
<ButtonGroup>
<ButtonGroup />
<ButtonGroup />
</ButtonGroup>
The ButtonGroupSeparator component visually divides buttons within a group.
| Prop | Type | Default |
|---|---|---|
orientation | "horizontal" | "vertical" | "vertical" |
<ButtonGroup>
<Button>Button 1</Button>
<ButtonGroupSeparator />
<Button>Button 2</Button>
</ButtonGroup>
Use this component to display text within a button group.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
<ButtonGroup>
<ButtonGroupText>Text</ButtonGroupText>
<Button>Button</Button>
</ButtonGroup>
Use the asChild prop to render a custom component as the text, for example a label.
import { ButtonGroupText } from "@/components/ui/button-group"
import { Label } from "@/components/ui/label"
export function ButtonGroupTextDemo() {
return (
<ButtonGroup>
<ButtonGroupText asChild>
<Label htmlFor="name">Text</Label>
</ButtonGroupText>
<Input placeholder="Type something here..." id="name" />
</ButtonGroup>
)
}