Bootstrap buttons are no different from any other DOM elements of an HTML document. Aligning them is more likely the same as aligning paragraphs, divs and sections. Here are some of the scenarios that one can encounter.
- Buttons in ‘container’ class:
Buttons in ‘container’ class can be aligned with the ‘text-align’ properties. Wrap the group of buttons inside a div and align them using the following classes,
Note: You can also use HTML5 <center> tag to align buttons to the center.
- Buttons inside FlexBox:
- .d-flex .flex-row
- .d-flex .flex-column
Another way of arranging buttons is by using flex-utilities. The basic flex classes provided by Bootstrap are
The following pattern can be achieved by choosing either one of them.
- Relative-Absolute method:
- Vertical alignment in Bootstrap with Examples
- BootStrap | Text Utilities (Alignment, Wrapping, Weight etc.)
- How to create a radio button similar to toggle button using Bootstrap ?
- How to set div with left image and button at bottom using bootstrap?
- Include Bootstrap in AngularJS using ng-bootstrap
- Difference between bootstrap.css and bootstrap-theme.css
- Difference Between Bootstrap 3 and Bootstrap 4
- Difference between Bootstrap 4 and Bootstrap 5
- Bootstrap 4 | Button Groups
- How to load notification alert on top right corner without click of button in bootstrap ?
- How to place button in top Right corner using bootstrap?
- How to align button to right side of text box in Bootstrap?
- How to enable Bootstrap tooltip on disabled button ?
- How to change (-, +) symbol with a button in Bootstrap Accordion ?
- How to make bootstrap button transparent ?
- How to change the position of modal close button in bootstrap?
- Bootstrap 5 | Button group
- Bootstrap 5 | Close button
- button tag vs input type="button" attribute
This is the most used method present online. In this case, the parent div is assigned a position ‘relative’ while the child divs are assigned position ‘absolute’.
Elements inside ‘absolute’ divs can be aligned in whatever way you want. Consider the following example. It shows all possible alignments a DOM element, in this case, buttons can have.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.