Bootstrap Button Group
Button groups allow multiple buttons to be stacked on the same line. This is very useful when you want to align buttons together. You can use the Bootstrap Button Plugin to add optional JavaScript radio and checkbox style behavior.
The following table summarizes some important classes provided by Bootstrap for use with button groups:
| Class | Description | Code Example |
|---|---|---|
| .btn-group | This class is used to form a basic button group. Place a series of buttons .btn-group with class .btn inside it. |
| onSelect | event | .btn-group-lg, .btn-group-sm, .btn-group-xs | These classes can be applied to size an entire button group, without having to size each button individually. |......
| onSelect | event | .btn-group-vertical | This class makes a group of buttons stack vertically instead of horizontally. |.........
|...
Basic button group
The following example demonstrates the classes discussed in the table above .btn-group :
Example
<div class="btn-group">
<button type="button" class=">btn btn-default
"
Button 1
button
<button type="button" class=">btn btn-default
"
Button 2
button
<button type="button" class=">btn btn-default
"
Button 3
button
div
Try it »
The result is as follows:
Button toolbar
The following example demonstrates the classes discussed in the table above .btn-toolbar :
Example
<div class="btn-toolbar" role="toolbar">
<div class="btn-group">
<button type="button" class=">btn btn-default
"
Button 1
button
<button type="button" class=">btn btn-default
"
Button 2
button
<button type="button" class=">btn btn-default
"
Button 3
button
div
<div class="btn-group">
<button type="button" class=">btn btn-default
"
Button 4
button
<button type="button" class=">btn btn-default
"
Button 5
button
<button type="button" class=">btn btn-default
"
Button 6
button
div
<div class="btn-group">
<button type="button" class=">btn btn-default
"
Button 7
button
<button type="button" class=">btn btn-default
"
Button 8
button
<button type="button" class=">btn btn-default
"
Button 9
button
div
div
Try it »
The result is as follows:
Button sizes
The following example demonstrates the classes discussed in the table above .btn-group-* usage:
Example
<div class=">btn-group btn-group-lg
"
<button type="button" class=">btn btn-default
"
Button 1
button
<button type="button" class=">btn btn-default
"
Button 2
button
<button type="button" class=">btn btn-default
"
Button 3
button
div
<div class=">btn-group btn-group-sm
"
<button type="button" class=">btn btn-default
"
Button 4
button
<button type="button" class=">btn btn-default
"
Button 5
button
<button type="button" class=">btn btn-default
"
Button 6
button
div
<div class=">btn-group btn-group-xs
"
<button type="button" class=">btn btn-default
"
Button 7
button
<button type="button" class=">btn btn-default
"
Button 8
button
<button type="button" class=">btn btn-default
"
Button 9
button
div
Try it »
The result is as follows:
Nested
You can nest another button group inside a button group, that is, inside a .btn-group nest another **.btn-group **. This is used when you want to combine a dropdown menu with a series of buttons.
Example
<div class="btn-group">
<button type="button" class=">btn btn-default
"
Button 1
button
<button type="button" class=">btn btn-default
"
Button 2
button
<div class="btn-group">
<button type="button" class=">btn btn-default dropdown-toggle
"
data-toggle
=
"
dropdown
"
Dropdown
<span class="caret" span button>
<ul class="dropdown-menu">
<li>
<a href="">Dropdown link 1
a
li
<li>
<a href="">Dropdown link 2
a
li
ul
div
div
Try it »
The result is as follows:
Vertical button group
The following example demonstrates the classes discussed in the table above .btn-group-vertical :
Example
<div class="btn-group-vertical">
<button type="button" class=">btn btn-default
"
Button 1
button
<button type="button" class=">btn btn-default
"
Button 2
button
<div class="btn-group-vertical">
<button type="button" class=">btn btn-default dropdown-toggle
"
data-toggle
=
"
dropdown
"
Dropdown
<span class="caret" span button>
<ul class="dropdown-menu">
<li>
<a href="">Dropdown link 1
a
li
<li>
<a href="">Dropdown link 2
a
li
ul
div
div
Try it »
The result is as follows: