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 groups.
Example:
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Button Groups</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href= <script src= </script> <script src= </script> <script src= </script> </head> <body> <div class="container"> <div class="btn-group"> <button type="button" class="btn btn-success"> HTML </button> <button type="button" class="btn btn-success"> CSS </button> <button type="button" class="btn btn-success"> JavaScript </button> </div> </div> </body> </html> |
Output:

Vertically arranged button groups: The .btn-group-vertical class is used in parent div to create vertical button group.
Example:
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Button Groups</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href= <script src= </script> <script src= </script> <script src= </script> </head> <body> <div class="container"> <div class="btn-group-vertical"> <button type="button" class="btn btn-success"> HTML </button> <button type="button" class="btn btn-success"> CSS </button> <button type="button" class="btn btn-success"> JavaScript </button> </div> </div> </body> </html> |
Output:

Button group sizing: The whole button group can be given the same size by including the class btn-group-* (* could be sm, md or lg) in the .btn-group parent element, instead of including sizing classes in each button.
Example:
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Button Groups</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href= <script src= </script> <script src= </script> <script src= </script> </head> <body> <div class="container"> <div class="btn-group btn-group-lg"> <button type="button" class="btn btn-success"> HTML </button> <button type="button" class="btn btn-success"> CSS </button> <button type="button" class="btn btn-success"> JavaScript </button> </div> <br><br> <div class="btn-group btn-group-md"> <button type="button" class="btn btn-success"> HTML </button> <button type="button" class="btn btn-success"> CSS </button> <button type="button" class="btn btn-success"> JavaScript </button> </div> <br><br> <div class="btn-group btn-group-sm"> <button type="button" class="btn btn-success"> HTML </button> <button type="button" class="btn btn-success"> CSS </button> <button type="button" class="btn btn-success"> JavaScript </button> </div> </div> </body> </html> |
Output:

Nesting button groups and making dropdown menus: A button group can be nested within another button group and dropdown menus can be created this way.
-
Single button dropdown:
Example:
<!DOCTYPE html><htmllang="en"><head><title>Bootstrap Button Groups</title><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1"><linkrel="stylesheet"href=<scriptsrc=</script><scriptsrc=</script><scriptsrc=</script></head><body><divclass="container"><divclass="btn-group"><buttontype="button"class="btn btn-success">HTML</button><buttontype="button"class="btn btn-success btn-group">CSS</button><divclass="btn-group"><buttontype="button"class="btn btn-success dropdown-toggle"data-toggle="dropdown">JavaScript<spanclass="caret"></span></button><ulclass="dropdown-menu"role="menu"><li><ahref="#">React</a></li><li><ahref="#">Vue</a></li></ul></div></div></div></body></html>chevron_rightfilter_noneOutput:
-
Split button dropdown:
Example:
<!DOCTYPE html><htmllang="en"><head><title>Bootstrap Button Groups</title><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1"><linkrel="stylesheet"href=<scriptsrc=</script><scriptsrc=</script><scriptsrc=</script></head><body><divclass="container"><divclass="btn-group"><buttontype="button"class="btn btn-success">HTML</button><buttontype="button"class="btn btn-success btn-group">CSS</button><divclass="btn-group"><buttontype="button"class="btn btn-success">JavaScript</button><buttontype="button"class="btn btn-success dropdown-toggle"data-toggle="dropdown"><spanclass="caret"></span></button><ulclass="dropdown-menu"role="menu"><li><ahref="#">React</a></li><li><ahref="#">Vue</a></li></ul></div></div></div></body></html>chevron_rightfilter_noneOutput:

However, the split button dropdown does not work as expected when the buttons are nested under .btn-group-vertical class.
Example:
<!DOCTYPE html><htmllang="en"><head><title>Bootstrap Button Groups</title><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1"><linkrel="stylesheet"href=<scriptsrc=</script><scriptsrc=</script><scriptsrc=</script></head><body><divclass="container"><divclass="btn-group-vertical"><buttontype="button"class="btn btn-success">HTML</button><buttontype="button"class="btn btn-success">CSS</button><divclass="btn-group"><buttontype="button"class="btn btn-success dropdown-toggle"data-toggle="dropdown">JavaScript</button><ulclass="dropdown-menu"role="menu"><li><ahref="#">React</a></li><li><ahref="#">Vue</a></li></ul></div></div></div></body></html>chevron_rightfilter_noneOutput:
Recommended Posts:
- Bootstrap 4 | List Groups
- Bootstrap 4 | Input Groups
- How to set the button alignment in Bootstrap ?
- Input Groups in Bootstrap with Examples
- How to place button in top Right corner using bootstrap?
- How to enable Bootstrap tooltip on disabled button ?
- How to align button to right side of text box in Bootstrap?
- How to load notification alert on top right corner without click of button in bootstrap ?
- button tag vs input type="button" attribute
- Include Bootstrap in AngularJS using ng-bootstrap
- Button in Kotlin
- HTML | button Tag
- groups command in Linux with examples
- HTML | DOM button Object
- HTML <button> value Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai



