Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • BS5 Tutorial
  • BS5 Interview Questions
  • BS5 Layout
  • BS5 Content
  • BS5 Components
  • BS5 Helpers
  • BS5 Utilities
  • BS4 Tutorial
  • BS Tutorial
  • Bootstrap Cheatsheet
  • Tailwind
  • CSS Frameworks
  • HTML Formatter
Open In App
Next Article:
What are Button Groups in Bootstrap ?
Next article icon

What are Button Groups in Bootstrap ?

Last Updated : 05 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

"Button Groups" in Bootstrap is a class of name "btn-group" which is used to create a series of buttons in groups (without spaces) vertically or horizontally.

Syntax: This is the basic syntax of the button group class where each button has its own class of "btn".

<div class="btn-group">     <button type="button" class="btn">Click</button> </div>

Buttons have a default border-radius on the first and last buttons of the group.

Adding Styles on Buttons: Bootstrap allows you to add styles to your buttons using the following classes:

  • .btn-default
  • .btn-primary
  • .btn-success
  • .btn-info
  • .btn-warning
  • .btn-danger
  • .btn-link

Example: In this example, we will create button groups using Bootstrap.

HTML
<!DOCTYPE html> <html lang="en"> <head>     <title>Bootstrap Example</title>     <meta charset="utf-8">     <meta name="viewport"            content="width=device-width, initial-scale=1">     <link rel="stylesheet"            href= "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">     <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">     </script>     <script src= "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">     </script>     <script src= "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">     </script> </head>  <body>     <div class="btn-group">         <button type="button" class="btn btn-danger">Click</button>         <button type="button" class="btn btn-warning">Click</button>         <button type="button" class="btn btn-success">Click</button>     </div> </body> </html> 

Output:

Sizing of your Buttons: Bootstrap provides 4 button sizes which you can add directly to your buttons by adding an additional class of "btn-group-*" to your "btn-group" class. No need to add separate classes to each button.

All 4 sizes can be used as follows:

Example: In this example, we will size our button.

HTML
<!DOCTYPE html> <html lang="en"> <head>     <title>Bootstrap Example</title>     <meta charset="utf-8">     <meta name="viewport" content=         "width=device-width, initial-scale=1">     <link rel="stylesheet" href= "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">     <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">     </script>     <script src= "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">     </script>     <script src= "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">     </script> </head>  <body>     <div class="btn-group btn-group-lg">         <button type="button" class="btn btn-danger">Click</button>         <button type="button" class="btn btn-warning">Click</button>         <button type="button" class="btn btn-success">Click</button>     </div>     <div class="btn-group">         <button type="button" class="btn btn-danger">Click</button>         <button type="button" class="btn btn-warning">Click</button>         <button type="button" class="btn btn-success">Click</button>     </div>     <div class="btn-group btn-group-sm">         <button type="button" class="btn btn-danger">Click</button>         <button type="button" class="btn btn-warning">Click</button>         <button type="button" class="btn btn-success">Click</button>     </div>     <div class="btn-group btn-group-xs">         <button type="button" class="btn btn-danger">Click</button>         <button type="button" class="btn btn-warning">Click</button>         <button type="button" class="btn btn-success">Click</button>     </div> </body> </html> 

Output:

Vertical Button Groups: Bootstrap also supports vertical button groups stacked in a vertical manner rather than horizontally. Use the class "btn-group-vertical" to create a vertical button group:

Example: In this example, we will create vertical button groups.

HTML
<!DOCTYPE html> <html lang="en"> <head>     <title>Bootstrap Example</title>     <meta charset="utf-8">     <meta name="viewport" content=         "width=device-width, initial-scale=1">     <link rel="stylesheet" href= "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">     <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">     </script>     <script src= "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">     </script>     <script src= "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">     </script> </head>  <body>     <div class="btn-group-vertical">         <button type="button" class="btn btn-danger">Click</button>         <button type="button" class="btn btn-warning">Click</button>         <button type="button" class="btn btn-success">Click</button>     </div> </body> </html> 

Output:

Nesting of Buttons: Bootstrap allows you to create dropdown menus under your buttons through nesting. Add a class of  "btn-group" within your main "btn-group" class to have a dropdown menu within your button:

Example: In this example, we will create a nested button.

HTML
<!DOCTYPE html> <html lang="en"> <head>     <title>Bootstrap Example</title>     <meta charset="utf-8">     <meta name="viewport"            content="width=device-width, initial-scale=1">     <link rel="stylesheet"            href= "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">     <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">     </script>     <script src= "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">     </script>     <script src= "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">     </script> </head>  <body>     <div class="btn-group">         <button type="button" class="btn btn-danger">Click</button>         <button type="button" class="btn btn-warning">Click</button>         <div class="btn-group">             <button type="button"                      class="btn btn-success dropdown-toggle"                      data-bs-toggle="dropdown"                      aria-expanded="false">                  Dropdown             </button>             <ul class="dropdown-menu" aria-labelledby="btnGroupDrop1">                 <li><a class="dropdown-item" href="#">Item 1</a></li>                 <li><a class="dropdown-item" href="#">Item 2</a></li>             </ul>         </div>     </div> </body> </html> 

Output:


Next Article
What are Button Groups in Bootstrap ?

P

pihu24aru20pr
Improve
Article Tags :
  • Web Technologies
  • HTML
  • Bootstrap
  • HTML-Questions
  • Bootstrap-Questions

Similar Reads

    Bootstrap 4 | Button Groups
    Bootstrap offers classes which allow to group buttons along the same line, horizontally or vertically. The buttons to be grouped are nested inside a <div> element with the class .btn-group. Horizontally arranged button groups: The .btn-group class is used to create horizontally arranged button
    4 min read
    Bootstrap 5 Button Group Sizing
    Bootstrap 5 provides different classes that allow changing button group sizes. Instead of using button sizing classes to every button element in a group, we can just add .btn-group-* class to set the button size in a button group. Button Group Sizing Classes: .btn-group-lg: This class is used to cre
    4 min read
    Bootstrap 5 Input Group Button Addons
    Bootstrap 5 Input Groups are used to extend form controls by adding the buttons, text, or button groups before or after the text inputs, custom selects, or file inputs. Input Group Button Addons are used to extend form controls by adding buttons or button groups.Bootstrap 5 Input group Button Addons
    2 min read
    Bootstrap 5 Button group Nesting
    Bootstrap 5 Button group nesting is used to create a dropdown menu mixed with a series of buttons. To make the button group nesting, we will use .btn-group class. Button group nesting used Class: .btn-group: This class is used to create a button group nesting in a dropdown menu. Syntax: <div clas
    2 min read
    Bootstrap 5 List group Links and buttons
    Bootstrap 5 provides the List Group Links and Buttons items feature in which items are actionable and stored in form of a list. List groups are a flexible and powerful component for displaying a series of content. The List Group Links and Buttons items feature is used to indicate the item is current
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences