Button group
Angular Bootstrap 5 Button group component
Group a series of buttons together on a single line with the button group.
Basic example
Wrap a series of buttons with .btn
in .btn-group
.
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-primary" mdbRipple>Left</button>
<button type="button" class="btn btn-primary" mdbRipple>Middle</button>
<button type="button" class="btn btn-primary" mdbRipple>Right</button>
</div>
Ensure correct role
and provide a label:
In order for assistive technologies (such as screen readers) to convey that a series of
buttons is grouped, an appropriate role
attribute needs to be provided. For
button groups, this would be role="group"
, while toolbars should have a
role="toolbar"
.
In addition, groups and toolbars should be given an explicit label, as most assistive
technologies will otherwise not announce them, despite the presence of the correct role
attribute. In the examples provided here, we use
aria-label
, but alternatives such as aria-labelledby
can also be
used.
These classes can also be added to links. Use the .active
class to highlight a
link.
<div class="btn-group">
<a href="#!" class="btn btn-primary active" mdbRipple>Active link</a>
<a href="#!" class="btn btn-primary" mdbRipple>Link</a>
<a href="#!" class="btn btn-primary" mdbRipple>Link</a>
</div>
Outlined styles
Use the following button styles to show the colors only for the border of the element.
<div class="btn-group shadow-0" role="group" aria-label="Basic example">
<button type="button" class="btn btn-outline-secondary" data-mdb-color="dark">
Left
</button>
<button type="button" class="btn btn-outline-secondary" data-mdb-color="dark">
Middle
</button>
<button type="button" class="btn btn-outline-secondary" data-mdb-color="dark">
Right
</button>
</div>
Toolbar
Combine sets of button groups into button toolbars for more complex components. Use utility classes as needed to space out groups, buttons, and more.
<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
<div class="btn-group me-2" role="group" aria-label="First group">
<button type="button" class="btn btn-primary" mdbRipple>1</button>
<button type="button" class="btn btn-primary" mdbRipple>2</button>
<button type="button" class="btn btn-primary" mdbRipple>3</button>
<button type="button" class="btn btn-primary" mdbRipple>4</button>
</div>
<div class="btn-group me-2" role="group" aria-label="Second group">
<button type="button" class="btn btn-primary" mdbRipple>5</button>
<button type="button" class="btn btn-primary" mdbRipple>6</button>
<button type="button" class="btn btn-primary" mdbRipple>7</button>
</div>
<div class="btn-group" role="group" aria-label="Third group">
<button type="button" class="btn btn-primary" mdbRipple>8</button>
</div>
</div>
Feel free to mix input groups with button groups in your toolbars. Similar to the example above, you’ll likely need some utilities though to space things properly.
<div class="btn-toolbar mb-3" role="toolbar" aria-label="Toolbar with button groups">
<div class="btn-group me-2" role="group" aria-label="First group">
<button type="button" class="btn btn-primary" mdbRipple>1</button>
<button type="button" class="btn btn-primary" mdbRipple>2</button>
<button type="button" class="btn btn-primary" mdbRipple>3</button>
<button type="button" class="btn btn-primary" mdbRipple>4</button>
</div>
<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"
/>
</div>
</div>
<div
class="btn-toolbar justify-content-between"
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" mdbRipple>1</button>
<button type="button" class="btn btn-primary" mdbRipple>2</button>
<button type="button" class="btn btn-primary" mdbRipple>3</button>
<button type="button" class="btn btn-primary" mdbRipple>4</button>
</div>
<div class="input-group">
<div class="input-group-text" id="btnGroupAddon2">@</div>
<input
type="text"
class="form-control"
placeholder="Input group example"
aria-label="Input group example"
aria-describedby="btnGroupAddon2"
/>
</div>
</div>
Sizing
Instead of applying button sizing classes to every button in a group, just add
.btn-group-*
to each .btn-group
, including each one when nesting
multiple groups.
<!-- Large -->
<div class="btn-group btn-group-lg" role="group" aria-label="Basic example">
<button type="button" class="btn btn-primary" mdbRipple>Left</button>
<button type="button" class="btn btn-primary" mdbRipple>Middle</button>
<button type="button" class="btn btn-primary" mdbRipple>Right</button>
</div>
<!-- Standard -->
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-primary" mdbRipple>Left</button>
<button type="button" class="btn btn-primary" mdbRipple>Middle</button>
<button type="button" class="btn btn-primary" mdbRipple>Right</button>
</div>
<!-- Small -->
<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
<button type="button" class="btn btn-primary" mdbRipple>Left</button>
<button type="button" class="btn btn-primary" mdbRipple>Middle</button>
<button type="button" class="btn btn-primary" mdbRipple>Right</button>
</div>
Vertical variation
Use the following code to group a series of buttons in a vertical button group.
<div class="btn-group-vertical" role="group" aria-label="Vertical button group">
<button type="button" class="btn btn-primary" mdbRipple>Button</button>
<button type="button" class="btn btn-primary" mdbRipple>Button</button>
<button type="button" class="btn btn-primary" mdbRipple>Button</button>
<button type="button" class="btn btn-primary" mdbRipple>Button</button>
<button type="button" class="btn btn-primary" mdbRipple>Button</button>
<button type="button" class="btn btn-primary" mdbRipple>Button</button>
</div>
Colors
Choose from several predefined button styles, each serving its own semantic purpose, with a few extras thrown in for more control.
<div class="btn-group shadow-0" role="group">
<button type="button" class="btn btn-light" data-mdb-color="dark" mdbRipple>Left</button>
<button type="button" class="btn btn-light" data-mdb-color="dark" mdbRipple>Middle</button>
<button type="button" class="btn btn-light" data-mdb-color="dark" mdbRipple>Right</button>
</div>
<div class="btn-group shadow-0" role="group">
<button type="button" class="btn btn-link" data-mdb-color="dark" mdbRipple>Left</button>
<button type="button" class="btn btn-link" data-mdb-color="dark" mdbRipple>Middle</button>
<button type="button" class="btn btn-link" data-mdb-color="dark" mdbRipple>Right</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-primary" mdbRipple>Left</button>
<button type="button" class="btn btn-primary" mdbRipple>Middle</button>
<button type="button" class="btn btn-primary" mdbRipple>Right</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-success" mdbRipple>Left</button>
<button type="button" class="btn btn-success" mdbRipple>Middle</button>
<button type="button" class="btn btn-success" mdbRipple>Right</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-danger" mdbRipple>Left</button>
<button type="button" class="btn btn-danger" mdbRipple>Middle</button>
<button type="button" class="btn btn-danger" mdbRipple>Right</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-warning" mdbRipple>Left</button>
<button type="button" class="btn btn-warning" mdbRipple>Middle</button>
<button type="button" class="btn btn-warning" mdbRipple>Right</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-info" mdbRipple>Left</button>
<button type="button" class="btn btn-info" mdbRipple>Middle</button>
<button type="button" class="btn btn-info" mdbRipple>Right</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-dark" mdbRipple>Left</button>
<button type="button" class="btn btn-dark" mdbRipple>Middle</button>
<button type="button" class="btn btn-dark" mdbRipple>Right</button>
</div>
Button Group - API
Import
import { MdbRippleModule } from 'mdb-angular-ui-kit/ripple';
…
@NgModule ({
...
imports: [MdbRippleModule],
...
})
CSS variables
As part of MDB’s evolving CSS variables approach, Button group now use local CSS variables for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
Most of variables for .btn-group
are the same as for buttons.
// .btn-group,
// .btn-group-vertical
--#{$prefix}btn-box-shadow: #{$btn-box-shadow};
--#{$prefix}btn-hover-box-shadow: #{$btn-hover-box-shadow};
--#{$prefix}btn-focus-box-shadow: #{$btn-focus-box-shadow};
--#{$prefix}btn-active-box-shadow: #{$btn-active-box-shadow};
--#{$prefix}btn-group-transition: #{$btn-group-transition};
// .btn-group,
// .btn-group-lg > .btn,
// .btn-group-sm > .btn
--#{$prefix}btn-border-radius: #{$btn-border-radius};
SCSS variables
$btn-group-border-radius: calc(4px - 1px);
$btn-group-transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;