Type to generate UI components from text


Browse thousands of MUI, Tailwind, React components that are fully customizable and responsive.

Explore Components

Bootstrap Button Group: A Guide to Easy and Friendly UI

Bootstrap is a popular open-source framework for developing responsive and mobile-first websites. One of its key features is the ability to easily create and manage groups of buttons. These groups of buttons, known as “button groups”, are designed to enhance user interaction and improve the overall design of a web page. They allow developers to group a series of buttons on a single line or stack them in a vertical column, providing a clean and organized interface.

Button groups can be used in a variety of ways depending on the needs of the website. They can be used for navigational purposes, such as a set of filters or categories, or actions like editing, saving, or deleting items. The flexibility of button groups makes them a versatile tool for creating intuitive and user-friendly interfaces.

This article aims to provide a comprehensive guide to understanding and effectively using Bootstrap Button Groups. We will cover everything from the basics of using button groups, to advanced techniques like nesting and vertical variations. We will also provide practical examples and code snippets to illustrate these concepts.

Bootstrap Button & Button Group 5 Crash Course – Video Resources

Getting Started with Bootstrap Button Group

Before we delve deeper into the specifics of using Bootstrap Button Groups, let’s start with the basics of setting up your environment.


To get started with Bootstrap Button Groups, you need to have a basic understanding of HTML, CSS, and JavaScript. You should also be familiar with how to include external libraries in your project. This is because Bootstrap is an external library that provides pre-written CSS and JavaScript files to make development easier.

Including Bootstrap in Your Project

To use Bootstrap in your project, you need to include the Bootstrap CSS and JS files in your HTML file. There are several ways to do this:

  1. CDN (Content Delivery Network): You can use the CDN links provided by Bootstrap. This is the easiest method, but it requires an internet connection to load the files. Here’s how you can do it:

    <!-- CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
    <!-- JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
  2. Local Files: Alternatively, you can download the Bootstrap files and include them locally in your project. This requires more setup but gives you offline access to the files.

After including Bootstrap in your project, you can start using Bootstrap Button Groups. Let’s move on to the next section where we’ll dive into the basic usage of Bootstrap Button Groups.

Basic Usage of Bootstrap Button Group

Once you have included Bootstrap in your project, you can start using Bootstrap Button Groups. Here’s how you can get started:

Creating a Basic Button Group

A basic button group can be created by wrapping a series of buttons with the .btn class in a <div> element and applying the .btn-group class to it. Here’s a simple example:

<div class="btn-group" role="group" aria-label="Basic example">
 <button type="button" class="btn btn-secondary">Left</button>
 <button type="button" class="btn btn-secondary">Middle</button>
 <button type="button" class="btn btn-secondary">Right</button>

In this example, three buttons are grouped together on a single line. The role and aria-label attributes are used for accessibility, providing a label for screen readers.

By default, Bootstrap Button Groups organize buttons horizontally on a single line. This is suitable for creating cohesive button sets for actions like navigation or form submission. The example above demonstrates this horizontal arrangement.

Stacking Buttons in a Vertical Column

If you prefer a vertical layout, you can use the btn-group-vertical class. This class aligns the buttons in a vertical column within the button group container:

<div class="btn-group-vertical" role="group" aria-label="Vertical button group">
  <button type="button" class="btn btn-primary">Button 1</button>
  <button type="button" class="btn btn-secondary">Button 2</button>
  <button type="button" class="btn btn-success">Button 3</button>

This vertical arrangement is useful when you want to present a list of options or actions in a more compact and intuitive manner.

Now that we’ve covered the basics of creating and sizing button groups, let’s move on to more advanced topics such as different styles for button groups and advanced usages of button groups.

Are you searching for ways to enhance your team’s productivity? Explore Purecode AI, an AI custom component generator that covers everything from HTML and CSS to Tailwind, JavaScript, and more.

Different Styles for Bootstrap Button Groups

Enhancing the visual appeal of your Bootstrap Button Groups involves exploring various styling options. This section delves into two distinct styles: mixed styles, allowing the use of different color schemes for buttons within the same group, and outlined styles, enabling the incorporation of outlined buttons within a group.

Mixed Styles: Using Different Color Schemes

Bootstrap provides a rich set of color classes that can be seamlessly integrated into Button Groups. This feature allows you to create visually diverse button sets within the same group. Each button can have its own color, adding clarity and emphasis to specific actions.

Let’s consider an example where we mix different color styles within a single button group:

<div class="btn-group" role="group" aria-label="Mixed Style Example">
  <button type="button" class="btn btn-primary">Primary</button>
  <button type="button" class="btn btn-success">Success</button>
  <button type="button" class="btn btn-danger">Danger</button>

In this illustration, each button adopts a distinct color scheme (Primary, Success, and Danger) while being part of the same group. This allows for a visually appealing and intuitive representation of diverse actions or choices.

Outlined Styles: Using Outlined Buttons

For a more subtle and refined appearance, Bootstrap offers the option to use outlined buttons within a Button Group. Outlined buttons have transparent backgrounds, making them suitable for scenarios where a minimalistic design is preferred.

To implement outlined styles, you can use the btn-outline-* classes along with the standard btn class. Here’s an example:

<div class="btn-group" role="group" aria-label="Outlined Style Example">
  <button type="button" class="btn btn-outline-primary">Primary</button>
  <button type="button" class="btn btn-outline-secondary">Secondary</button>
  <button type="button" class="btn btn-outline-success">Success</button>

In this case, the buttons within the group have outlined borders and inherit their color from the respective btn-outline-* class. This creates a clean and modern look, particularly suitable for interfaces where a more subdued design is desired.

Choosing the Right Style for Your Design

The decision to use mixed or outlined styles in your Bootstrap Button Groups depends on the overall design goals and user experience you aim to achieve. Mixed styles add vibrancy and emphasize distinctions, while outlined styles offer a more understated and sophisticated appearance.

Experiment with these styling options to find the perfect balance for your project. By leveraging Bootstrap’s versatile styling features, you can create Button Groups that not only enhance functionality but also contribute to a visually engaging user interface.

With this knowledge, you can add stylish and visually appealing button groups to your Bootstrap projects. However, Bootstrap button groups aren’t limited to just these styles. Let’s move on to advanced usages of button groups.

Advanced Usages of Bootstrap Button Group

As we delve deeper into the capabilities of Bootstrap Button Groups, this section explores advanced usages that go beyond the basics. Discover how to harness the power of nesting, allowing the placement of one .btn-group within another, and explore vertical variation to present a set of buttons in a stacked, vertical layout.

Nesting: Creating Hierarchical Button Groups

Nesting is a powerful feature in Bootstrap Button Groups that allows you to organize buttons hierarchically. This is particularly useful when you combine dropdown menus with a series of buttons, creating a more sophisticated user interface.

Consider the following example:

<div class="btn-group" role="group" aria-label="Nested Example">
  <button type="button" class="btn btn-primary">Button 1</button>
  <button type="button" class="btn btn-secondary">Button 2</button>
  <!-- Nested Button Group with Dropdown -->
  <div class="btn-group" role="group">
    <button id="dropdownMenuButton" type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
      <a class="dropdown-item" href="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <a class="dropdown-item" href="#">Something else here</a>

In this example, the outer .btn-group encompasses two regular buttons, while the inner .btn-group contains a button that triggers a dropdown menu. This nesting approach allows you to create complex button structures, combining standard buttons with dropdown functionality seamlessly.

Bootstrap Group Nesting – Video Resources

To make the dropdown menu function, you will need to write a simple script.

    // Initializing the Bootstrap dropdown
    const myDropdown = new bootstrap.Dropdown(document.getElementById('myDropdown'));

    // Event handling for when the dropdown is about to be shown
    myDropdown._element.addEventListener('show.bs.dropdown', function () {
        console.log('Dropdown is about to be shown');
        // Custom logic when the dropdown is about to be shown

    // Event handling for when the dropdown is about to be hidden
    myDropdown._element.addEventListener('hide.bs.dropdown', function () {
        console.log('Dropdown is about to be hidden');
        // Custom logic when the dropdown is about to be hidden

    // Event handling for when a dropdown item is clicked
    myDropdown._element.addEventListener('click.bs.dropdown', function (event) {
        const selectedItem = event.target; // Access the clicked item
        console.log('Item clicked:', selectedItem.textContent);
        // Custom logic for handling item selection

Rounded Pill Outline

For a unique look, you can use the .rounded-pill class along with the .btn-group class to create a rounded pill outline for your button group. Here’s an example:

<div class="btn-group rounded-pill" role="group" aria-label="Outline example">
 <button type="button" class="btn btn-outline-primary">Left</button>
 <button type="button" class="btn btn-outline-primary">Middle</button>
 <button type="button" class="btn btn-outline-primary">Right</button>

In this example, the button group has a rounded pill outline.

With these advanced techniques, you can create more complex and visually interesting button groups for your projects. However, there’s even more to explore. Let’s move on to combining sets of button groups into button toolbars.

Customizing Advanced Usages

When implementing nested or vertically stacked button groups, consider additional customization options available in Bootstrap. You can apply color schemes, sizing options, and other styling features to tailor the appearance to your specific design requirements.

Experimenting with these advanced usages allows you to create intricate and responsive button layouts that enhance both functionality and aesthetics. Bootstrap’s flexibility empowers developers to design interfaces that cater to diverse user interactions and design preferences.

Button Toolbar

A button toolbar in Bootstrap is a container that combines sets of button groups into a single component. It’s a powerful feature that allows you to create complex user interfaces with ease. This section explores how to combine sets of button groups into button toolbars, providing a versatile approach to building sophisticated user interfaces. Additionally, we’ll delve into the integration of input groups with button groups within toolbars for added flexibility.

Bootstrap Button Toolbar – Video Resources

Creating a Button Toolbar

Creating a button toolbar is straightforward. You simply wrap a series of button groups in a <div> element and apply the .btn-toolbar class to it. Here’s an example:

<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
 <div class="btn-group" role="group" aria-label="First group">
   <button type="button" class="btn btn-primary">1</button>
   <button type="button" class="btn btn-primary">2</button>
   <button type="button" class="btn btn-primary">3</button>
   <button type="button" class="btn btn-primary">4</button>

In this example, a button toolbar is created with one button group containing four buttons.

Combining Button Groups into Button Toolbars

Button Toolbars in Bootstrap allow developers to consolidate sets of button groups, creating cohesive and organized components. This is particularly beneficial when designing complex navigation menus or feature-rich interfaces. To initiate a Button Toolbar, you can use the .btn-toolbar class along with the standard .btn-group class for individual button groups.

Consider the following example:

<div class="btn-toolbar" role="toolbar" aria-label="Button Toolbar Example">
  <!-- First Button Group -->
  <div class="btn-group" role="group" aria-label="First Group">
    <button type="button" class="btn btn-primary">Button 1</button>
    <button type="button" class="btn btn-secondary">Button 2</button>
    <button type="button" class="btn btn-success">Button 3</button>

  <!-- Second Button Group -->
  <div class="btn-group" role="group" aria-label="Second Group">
    <button type="button" class="btn btn-info">Button 4</button>
    <button type="button" class="btn btn-warning">Button 5</button>

In this example, the .btn-toolbar class encapsulates two distinct button groups. This organization enhances the visual structure of the buttons and facilitates better management of related actions or functionalities within your design.

Combining Button Groups and Input Groups

You can also combine button groups with input groups within a button toolbar. This can be useful when you want to create a form with grouped inputs and associated buttons. Here’s an example:

<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups and input groups">
 <div class="btn-group me-2" role="group" aria-label="First group">
   <button type="button" class="btn btn-primary">1</button>
   <button type="button" class="btn btn-primary">2</button>
   <button type="button" class="btn btn-primary">3</button>
   <button type="button" class="btn btn-primary">4</button>
 <div class="input-group">
   <div class="input-group-text" id="btnGroupAddon">@</div>
   <input type="text" class="form-control" placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon">

Adding Keyboard Navigation

For better accessibility, you can add keyboard navigation to your button toolbar. This allows users to navigate through the toolbar using the arrow keys. Unfortunately, Bootstrap doesn’t provide built-in keyboard navigation for button toolbars, so you’ll need to implement this functionality yourself or use a third-party library.

With these techniques, you can create complex and interactive button toolbars for your projects. However, there’s still more to explore. Let’s move on to the final section of our guide, where we’ll provide several practical examples of how to use Bootstrap Button Groups in various scenarios.

Importance and Usage of Bootstrap Button Group

Group Related ActionsButton groups allow you to group related actions together, making your interface cleaner and easier to use. They can be used in various places like navigation bars, forms, and toolbars.
Improve User ExperienceBy grouping related actions, users can quickly perform a series of actions without having to navigate through multiple menus or pages. This can significantly improve the user experience of your application.
Enhance Visual AppealButton groups can enhance the visual appeal of your application by providing a consistent look and feel. You can customize the color, size, shape, and style of the buttons in a group to match the overall design of your application.
Create Complex ComponentsButton groups can be combined with other Bootstrap components like dropdown menus and input groups to create complex components like button toolbars. These can be used to build interactive and dynamic user interfaces.
Ensure AccessibilityButton groups are essential for ensuring accessibility. By grouping related buttons, you can ensure that assistive technologies like screen readers can correctly interpret and interact with the buttons.

What we have covered so far?

In conclusion, Bootstrap Button Groups are a versatile and powerful tool for enhancing user interaction and improving the visual appeal of your web pages. With their flexibility and customization options, they can be adapted to suit a wide range of design needs.

We’ve explored the basics of getting started with Bootstrap Button Groups, learned how to create and style button groups, and seen how to use them in advanced ways like nesting and creating button toolbars. We’ve also looked at practical examples of how to use button groups in real-world scenarios.

However, as with any tool, it’s important to understand potential pitfalls and limitations. For instance, while Bootstrap does provide a lot of flexibility in terms of styling, it may not always align perfectly with every design requirement. Additionally, while Bootstrap’s button groups are easy to use, they do require a certain level of familiarity with HTML, CSS, and JavaScript, as well as the Bootstrap framework itself.

If you use Bootstrap for your project, consider using Purecode AI to access over 10000+ AI-generated ready-made templates and components to speed up your development process. Avoid the hassle with Purecode.

Victor Yakubu

Victor Yakubu